protected string GetHTTPReponse(string url, string webcode)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = null;
if (webcode.ToLower() == "gb2312")
{
reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
}
else if (webcode.ToLower() == "utf-8")
{
reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
}
else
{
reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
}
StringBuilder builder = new StringBuilder();
builder.Append(reader.ReadToEnd());
reader.Close();
return builder.ToString();
}
catch (Exception err)
{
return string.Empty;
}
}
获取HTML页面源代码
最新推荐文章于 2024-06-18 10:10:15 发布