Reputation: 3218
I am able to send a POST request with string parameters to an URL using the System.Web.HttpClient
like so:
// Create the HTTPClient
HttpClient httpClient = new HttpClient();
// Add string parameters
FormUrlEncodedContent content = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("client_id", "myclientid),
new KeyValuePair<string, string>("serial_number", "myserialnumber)
});
// Make the call
HttpResponseMessage response = await httpClient.PostAsync(_requestUri, content);
However, I want to do the same, but with the Windows.Web.HttpClient
class.
The main difference is that the PostAsync
method accepts an HttpContent as the second argument, so my FormUrlEncodedContent
does not work. Also I cannot create an IHttpContent
with JSON since I need to pass string parameters.
Any thoughts?
Upvotes: 1
Views: 4470
Reputation: 173
Take a look at
http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.httpformurlencodedcontent
I reckon all you need is to create a HttpFormUrlEncodedContent
object instead and pass that in. It implements the IHTTPContext
interface which is what your after
Upvotes: 2