Gto*_*ria 3 c# windows-phone-8
此代码适用于Windows窗体:
string URI = "http://localhost/1/index.php?dsa=232323";
string myParameters = "";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
Run Code Online (Sandbox Code Playgroud)
但我想从Windows Phone 8发送http GET请求.在wp 8中没有方法UploadString()等等......
只需使用HttpClient即可
using(HttpClient hc = new HttpClient())
{
var response = await hc.PostAsync(url,new StringContent (yourString));
}
Run Code Online (Sandbox Code Playgroud)
对于您的情况,您可以上传FormUrlEncodedContent内容,而不是手动形成上传字符串.
using(HttpClient hc = new HttpClient())
{
var keyValuePairs = new Dictionary<string,string>();
// Fill keyValuePairs
var content = new FormUrlEncodedContent(keyValuePairs);
var response = await hc.PostAsync(url, content);
}
Run Code Online (Sandbox Code Playgroud)