简体   繁体   English

HTTPClient帖子无法正常工作Windows Phone Silverlight

[英]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? 但是我在FormUrlEncodedContentFormUrlEncodedContent 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.

相关问题 ContactPicker无法在Windows Phone 8.1 Silverlight中运行 - ContactPicker is not working in Windows Phone 8.1 Silverlight 扩展方法在Silverlight Windows Phone 7中不起作用 - Extension method not working in silverlight windows phone 7 Windows手机应用,Windows.Web.Http.HttpClient帖子示例 - Windows phone app, Windows.Web.Http.HttpClient post sample 使用HTTPClient发布图像以及Windows Phone上的一些参数 - Post an image with HTTPClient but also some parameters on windows phone Windows Phone 8 HttpClient未响应所有发布数据 - Windows Phone 8 HttpClient didn't response all Post data 使用HttpClient通过HTTP POST Windows Phone 8.1上传图像和字符串 - Upload image and string via HTTP POST windows phone 8.1 with HttpClient 在 Windows Phone 8 中使用 HttpClient 执行 POST 时出现内部服务器错误 - Internal Server Error when doing a POST with HttpClient in Windows Phone 8 如何在 Windows Phone 8 的 HttpClient 请求中发送 Post 正文? - How to send a Post body in the HttpClient request in Windows Phone 8? Windows Phone WEB API通过HttpClient发布404错误 - Windows Phone WEB API Post via HttpClient Returning 404 Error Windows Phone 8中没有HttpClient缓存 - No cache with HttpClient in Windows Phone 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM