码迷,mamicode.com
首页 > 其他好文 > 详细

外部请求

时间:2016-06-08 12:28:25      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
/// 向Url发送post请求
/// </summary>
/// <param name="postData">发送数据</param>
/// <param name="uriStr">接受数据的Url</param>
/// <returns>返回网站响应请求的回复</returns>
public static string RequestGet(string URL)
{

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Credentials = CredentialCache.DefaultCredentials;

request.Method = "get";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";

Stream responseStream = null;
try { responseStream = request.GetResponse().GetResponseStream(); }
catch (Exception e) { throw e; }
string stringResponse = string.Empty;
using (StreamReader responseReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
stringResponse = responseReader.ReadToEnd();
}
responseStream.Close();
return stringResponse;
}

外部请求

标签:

原文地址:http://www.cnblogs.com/chj929555796/p/5569549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!