HTTP GET从Windows手机8请求 [英] Http GET request from windows phone 8

查看:184
本文介绍了HTTP GET从Windows手机8请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在Windows上运行的形式:

This code works on windows forms :

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);
}



但我想从Windows手机发送8 HTTP GET请求。在WP 8有没有方法 UploadString()等...

推荐答案

只需使用 HttpClient的

using(HttpClient hc = new HttpClient())
{
    var response = await hc.PostAsync(url,new StringContent (yourString));
}

和你的情况,你可以上传 FormUrlEncodedContent 内容,而不是手动形成上传字符串。

And for your case, you can upload FormUrlEncodedContent content instead of forming upload string manually.

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);
}

这篇关于HTTP GET从Windows手机8请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆