//
// 摘要:
// GET请求
//
// 参数:
// Url:
// The URL.
//
// postDataStr:
// The post data string.
//
// 返回结果:
// System.String.
public static string HttpGet(string Url, string postDataStr = "")
{
Url = ((Url.IndexOf("?") != -1) ? Url : (Url + ((postDataStr == "") ? "" : "?") + postDataStr));
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
httpWebRequest.Method = "GET";
httpWebRequest.ContentType = "text/html;charset=UTF-8";
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
string result = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
return result;
}
C# HttpGet
最新推荐文章于 2024-08-20 21:46:40 发布