外部请求
Posted D调灬仔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了外部请求相关的知识,希望对你有一定的参考价值。
/// <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;
}
以上是关于外部请求的主要内容,如果未能解决你的问题,请参考以下文章