c# - 在 Windows Phone 上发布请求

标签 c# windows-phone-7 webclient

我试图用我的 Windows Phone 在网络服务器上发出请求,但我不工作。

我有这段代码可以在我的电脑上运行

var client = new WebClient
        {
            BaseAddress = "https://xxx.xxx-xxx.com/"
        };

        var values = new NameValueCollection
        {
            {"wrap_name", userName},
            {"wrap_password", password},
            {"wrap_scope", scope}
        };

        // WebClient takes care of URL Encoding
        var responseBytes = client.UploadValues("issue/wrap", "POST", values);

我知道 client.UploadValues 在 Windows Phone 上不可用。所以我在我的 wp 上做了这段代码

            var email = "xxx@xxx.org";
            var password = "xxx";
            var data = "wrap_name=" + email + "&wrap_password=" + password + "&wrap_scope=http://xxx.com/";
            var url = "https://xxx.xxx-xxx.com/issue/wrap";

                            var wc = new WebClient { 
                //BaseAddress = "https://login.solar-inverter.com/"
            };
            var URI = new Uri(url);
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc__UploadStringCompleted);

            wc.UploadStringAsync(URI, "POST", data); 

我使用 fiddler,我得到了这个 Image from fiddler

谁能帮帮我

提前致谢

最佳答案

  1. 您应该先对电子邮件和密码字段进行 URLEncode,然后再将它们添加到帖子正文字符串中。
  2. 您应该添加一个 Content-Type 请求 header ,其值为 application/x-www-form-urlencoded

您可以使用 Fiddler 的比较 session 功能来比较工作请求和非工作请求,并调整非工作请求以完全匹配工作请求。

关于c# - 在 Windows Phone 上发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16987464/

相关文章:

windows-phone-7 - PushPin 中的自定义模板

.net - 通过 WebClient.DownloadData 自动解压缩 gzip 响应

c# - 如何使用c#从谷歌驱动器下载文件

c# - 使用 Watin 的 ASP.NET Web 应用程序

C# 和 win32 API。在两个桌面之间切换。如何回到原来的桌面?

silverlight - MVVM Light、Windows Phone、View & ViewModel 在页面之间导航

powershell - 有没有办法在powershell中使用WebClient对象来监控下载进度?

C# 从 URL 中读取文件信息

c# - ds.Tables[0].Select() 代表什么

c# - 要旋转的数据绑定(bind)列表