此代码适用于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请求


基础教程推荐
猜你喜欢
- unity实现场景跳转 2023-04-14
- c# 使用Entity Framework操作Access数据库的示例 2022-11-22
- Linux下安装SkyWalking 6.x版本 以及.NETCore项目集成 2023-09-28
- Unity游戏开发中的设计模式之策略模式 2023-07-19
- Unity 使用tiledmap解析地图的详细过程 2023-05-30
- 深入理解C#管道式编程 2023-04-21
- c# – 如何获取正在运行的进程的ExitCode 2023-09-19
- c#如何实现接口事件 2023-03-13
- C#单例模式(Singleton Pattern)详解 2022-11-13
- C#图像处理的多种方法 2022-12-31