0

我正在尝试通过 POST 请求将通知链接和设备 ID 发送到网络上的脚本。问题是脚本只接收空参数。我遵循了另一个示例,我的代码如下所示:

WebClient wc = new WebClient();
            System.Diagnostics.Debug.WriteLine("sending rquest");
            var URI = new Uri("http://www.jack-prove.comuv.com/update_link.php");
            wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
            byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            string ID = Convert.ToBase64String(myDeviceID);
            String par = "?link=" + e.ChannelUri.ToString() + "&ID=" + ID;
            MessageBox.Show(par);
            wc.UploadStringAsync(URI, "POST", par);

注意:ID 字符串包含一个“=”字符,这可能是问题吗?我试图从网络上调用脚本,它甚至可以使用“=”

任何想法?

4

1 回答 1

0

解决了,感谢这个问题

使用Http 客户端库

using System.Net.Http;
var values = new List<KeyValuePair<string, string>>
{
      new KeyValuePair<string, string>("link", e.ChannelUri.ToString()),
      new KeyValuePair<string, string>("ID", ID)
};
var httpClient = new HttpClient(new HttpClientHandler());
HttpResponseMessage response = await httpClient.PostAsync(URI, new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
于 2013-09-20T09:00:07.777 回答