HTTPClient帖子不工作windows手机silverlight

时间:2015-05-22 10:16:47

标签: c# silverlight windows-phone httpclient

我正在制作一个Silverlight应用程序。现在我有这个函数用于POST

int

但我在 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(); } 上构建错误可以有人帮忙吗?

这是错误:

FormUrlEncodedContent

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我最终要做的是从NuGet安装Microsoft.Net.Http包。

右键单击解决方案资源管理器中的项目名称。
管理NuGet包。
搜索&#34; microsoft.net.http&#34;。
安装。

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)
{

}

(在Windows Phone 8.1和10上测试)