C# 下载网页
/// <summary>
/// 下载网页
/// </summary>
/// <param name="Url">网址</param>
/// <param name="myEncoding">编码</param>
/// <returns>网页内容</returns>
public static string DownHtml(string Url, Encoding myEncoding)
{
try
{
HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(Url);
loHttp.Timeout = 500;
HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), myEncoding);
string html = loResponseStream.ReadToEnd();
loWebResponse.Close();
return html;
}
catch
{
return null;
}
}
/// 下载网页
/// </summary>
/// <param name="Url">网址</param>
/// <param name="myEncoding">编码</param>
/// <returns>网页内容</returns>
public static string DownHtml(string Url, Encoding myEncoding)
{
try
{
HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(Url);
loHttp.Timeout = 500;
HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), myEncoding);
string html = loResponseStream.ReadToEnd();
loWebResponse.Close();
return html;
}
catch
{
return null;
}
}