HTTPClient post not working windows phone silverlight

本文关键字:phone silverlight windows working post not HTTPClient | 更新日期: 2023-09-27 17:50:32

我正在制作一个silverlight应用程序。现在我有了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();
        }

但是我gpt构建错误在FormUrlEncodedContent上,有人能帮助吗?

错误:

The type or namespace name 'FormUrlEncodedContent' could not be found (are you missing a using directive or an assembly reference?)

HTTPClient post not working windows phone silverlight

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

在解决方案资源管理器中右键单击项目名称。
管理NuGet包。
搜索"microsoft.net.http"。
安装。
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上测试)