Can't find how to use HttpContent

user1416156 picture user1416156 · Jun 21, 2012 · Viewed 241.5k times · Source

I am trying to use HttpContent:

HttpContent myContent = HttpContent.Create(SOME_JSON);

...but I am not having any luck finding the DLL where it is defined.

First, I tried adding references to Microsoft.Http as well as System.Net, but neither is in the list. I also tried adding a reference to System.Net.Http but the HttpContent class is not available.

So, can anyone tell me where I can find the HttpContent class?

Answer

Youngjae picture Youngjae · Jun 29, 2014

Just use...

var stringContent = new StringContent(jObject.ToString());
var response = await httpClient.PostAsync("http://www.sample.com/write", stringContent);

Or,

var stringContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync("http://www.sample.com/write", stringContent);