我尝试通过POST请求将通知链接和deviceID发送到Web上的脚本。问题是脚本只接收空参数。 我跟着另一个例子,我的代码看起来像这样:
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字符串包含'='字符这可能是问题吗?我试图从网上调用脚本,它甚至可以使用'='
任何想法?
答案 0 :(得分:0)
解决了,感谢this question
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();