POSTing JsonObject With HttpClient From Web API POSTing JsonObject With HttpClient From Web API asp.net asp.net

POSTing JsonObject With HttpClient From Web API


With the new version of HttpClient and without the WebApi package it would be:

var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");var result = client.PostAsync(url, content).Result;

Or if you want it async:

var result = await client.PostAsync(url, content);


The easiest way is to use a StringContent, with the JSON representation of your JSON object.

httpClient.Post(    "",    new StringContent(        myObject.ToString(),        Encoding.UTF8,        "application/json"));