POSTing JsonObject With HttpClient From Web API

I’m trying to POST a JsonObject using HttpClient from Web API. I’m not quite sure how to go about this and can’t find much in the way of sample code.

Here’s what I have so far:

var myObject = (dynamic)new JsonObject();
myObject.Data = "some data";
myObject.Data2 = "some more data";

HttpClient httpClient = new HttpClient("myurl");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = httpClient.Post("", ???);

I think I need to cast my JsonObject as a StreamContent but I’m getting hung up on that step.

9 Answers
9

Leave a Comment