Sending asynchronous HTTP POST request with JSON body
suggest changepublic static async Task PostAsync(this Uri uri, object value)
{
var content = new ObjectContext(value.GetType(), value, new JsonMediaTypeFormatter());
using (var client = new HttpClient())
{
return await client.PostAsync(uri, content);
}
}
. . .
var uri = new Uri("http://stackoverflow.com/documentation/c%23/1971/performing-http-requests");
await uri.PostAsync(new { foo = 123.45, bar = "Richard Feynman" });
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents