此代码适用于Windows窗体:string URI = http://localhost/1/index.php?dsa=232323;string myParameters = ;using (WebClient wc = new WebClient()){wc.Headers[HttpRequestHeader.ContentType] = applicati...
此代码适用于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);
}
但是我想从Windows Phone 8发送http GET请求.在wp 8中没有方法UploadString()等…
解决方法:
只需使用HttpClient
using(HttpClient hc = new HttpClient())
{
var response = await hc.PostAsync(url,new StringContent (yourString));
}
对于您的情况,您可以上传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);
}
沃梦达教程
本文标题为:c#-来自Windows Phone 8的Http GET请求
猜你喜欢
- C# 枚举Color并展示各种颜色效果的示例 2023-04-22
- C# 列表List的常用属性和方法介绍 2023-04-10
- c#实现获取字符串阵列中元素最长或最短的长度 2022-11-28
- C#对Word文档的创建、插入表格、设置样式等操作实例 2022-12-11
- c# – 如何从MySQL中选择sum(max remaining(x y z))来捕获总和(1200 1300 1400) 2023-11-13
- 如何利用C#通过sql语句操作Sqlserver数据库教程 2023-07-05
- C#使用Log4.net记录日志文件 2023-05-31
- 在C#中如何使用Dapper详解(译) 2022-12-31
- C# 如何获取处于运行中的Excel、Word对象 2023-03-29
- C# 使用multipart form-data方式post数据到服务器 2023-03-09