[英]HTTPClient post not working windows phone silverlight
I'm making a silverlight application. 我正在申请Silverlight应用程序。 Now I have this function for doing a POST
现在我有执行POST的功能
public async Task<Webservice> addEvent()
{
var values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("email", "qewfwef"),
new KeyValuePair<string, string>("password", "qewfwef"),
new KeyValuePair<string, string>("firstname", "qewfwef"),
new KeyValuePair<string, string>("lastname", "qewfwef"),
new KeyValuePair<string, string>("picture", "123456")
};
var httpClient = new HttpClient(new HttpClientHandler());
HttpResponseMessage response = await httpClient.PostAsync(url, new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
}
But I gpt build errors on FormUrlEncodedContent
can anyone help? 但是我在
FormUrlEncodedContent
上FormUrlEncodedContent
gpt错误, FormUrlEncodedContent
可以帮忙吗?
This is the error: 这是错误:
The type or namespace name 'FormUrlEncodedContent' could not be found (are you missing a using directive or an assembly reference?)
I was having the same problem, and what I ended up having to do was install from NuGet the Microsoft.Net.Http package. 我遇到了同样的问题,最终要做的是从NuGet的Microsoft.Net.Http软件包中进行安装。
Right click project name in solution explorer. 在解决方案资源管理器中右键单击项目名称。
Manage NuGet Packages. 管理NuGet软件包。
Search for "microsoft.net.http". 搜索“ microsoft.net.http”。
Install. 安装。
string site = "https://www.yoursite.com";
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("email", "qewfwef"),
new KeyValuePair<string, string>("password", "qewfwef"),
new KeyValuePair<string, string>("firstname", "qewfwef"),
new KeyValuePair<string, string>("lastname", "qewfwef"),
new KeyValuePair<string, string>("picture", "123456")
};
var client = new System.Net.Http.HttpClient();
var content = new FormUrlEncodedContent(pairs);
System.Net.Http.HttpResponseMessage response = await client.PostAsync(site, content);
if (response.IsSuccessStatusCode)
{
}
(tested on windows phone 8.1 and 10) (在Windows Phone 8.1和10上测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.