windows phone 8.1 HttpWebRequest 请求服务器
2020-12-13 16:14
标签:style blog http color ar os sp div on 上面代码是GET方式请求; 这是POST请求方式 windows phone 8.1 HttpWebRequest 请求服务器 标签:style blog http color ar os sp div on 原文地址:http://www.cnblogs.com/shi-meng/p/4080848.htmlpublic string SendGetRequest(string baseurl, string parameters)
{
string parassb = parameters;
if (parassb.Length > 0)
{
baseurl += "?" + parassb;
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseurl);
req.Method = "GET";
req.ContinueTimeout = 1000;
string result = String.Empty;
using (StreamReader reader = new StreamReader(req.GetResponseAsync().Result.GetResponseStream()))
{
result = reader.ReadToEnd();
}
return result;
}
public async Taskstring> PostRequest(string url, string parameters)
{
var request = HttpWebRequest.Create(url);
request.Method = "POST";
using (Stream result = await request.GetRequestStreamAsync())
{
byte[] bytes = Encoding.UTF8.GetBytes(parameters);
result.Write(bytes, 0, bytes.Length);
}
var response = await request.GetResponseAsync();
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string content = reader.ReadToEnd();
return content;
}
}
return null;
}
上一篇:C# 接口开发小工具 笔记
文章标题:windows phone 8.1 HttpWebRequest 请求服务器
文章链接:http://soscw.com/essay/35915.html