[英]Send POST request with string parameters to an URL using Windows.Web.HttpClient PostAsync()
我可以使用System.Web.HttpClient
将带有字符串参数的POST请求发送到URL,如下所示:
// 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);
但是,我想使用Windows.Web.HttpClient
类执行相同的操作。
主要区别在于PostAsync
方法接受HttpContent作为第二个参数,因此我的FormUrlEncodedContent
不起作用。 另外,由于需要传递字符串参数,因此无法使用JSON创建IHttpContent
。
有什么想法吗?
看一眼
http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.httpformurlencodedcontent
我认为您所需要的只是创建一个HttpFormUrlEncodedContent
对象并将其传递给它。它实现了IHTTPContext
接口,这是您的IHTTPContext
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.