Jake Dawson
Jake Dawson

Reputation: 89

Making a post request to MVC Web API in WinRt?

I've been trying to make a post request to my WebApi. I'm supposed to send it as Json then the MVC api will convert it into the c# object is supposed to accept.

I use this code in C# to post the data as JSON:

 HttpClient httpClient = new HttpClient();
 string postData = JsonConvert.SerializeObject(dbsub);
 StringContent c = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
 httpClient.MaxResponseContentBufferSize = 100000;
 var result = await httpClient.PostAsync("http://127.0.0.1/api/Submissions", c);

The problem is in the server the objects properties are returned null. But Im not getting any errors...

Any idea on how to fix this or is there another way to post c# objects as JSON for MVC Web Api?

Upvotes: 1

Views: 812

Answers (1)

SLaks
SLaks

Reputation: 887857

You're lying about the data you POST.

If you serialize the data as JSON, you need to send the correct Content-Type of application/json.

Upvotes: 1

Related Questions