How to send a Post body in the HttpClient request in Windows Phone 8?

UPDATE 2:

From @Craig Brown:

As of .NET 5 you can do:
requestMessage.Content = JsonContent.Create(new { Name = "John Doe", Age = 33 });

See JsonContent class documentation

UPDATE 1:

Oh, it can be even nicer (from this answer):

requestMessage.Content = new StringContent("{\"name\":\"John Doe\",\"age\":33}", Encoding.UTF8, "application/json");

This depends on what content do you have. You need to initialize your requestMessage.Content property with new HttpContent. For example:

...
// Add request body
if (isPostRequest)
{
    requestMessage.Content = new ByteArrayContent(content);
}
...

where content is your encoded content. You also should include correct Content-type header.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)