/// <summary>
/// 获取网站HTML内容
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public string GetHtmlContent(string address)
{
string resultStr = string.Empty;
HttpWebRequest hreq = null;
HttpWebResponse hrep = null;
Stream stream = null;
StreamReader sReader = null;
try
{
hreq = (HttpWebRequest)WebRequest.Create(address);
hreq.Timeout = 10000000;
hrep = (HttpWebResponse)hreq.GetResponse();
stream = hrep.GetResponseStream();
sReader = new StreamReader(stream, System.Text.Encoding.Default);
resultStr = sReader.ReadToEnd();
}
catch (Exception exp)
{
throw exp;
}
finally
{
if (sReader != null)
sReader.Close();
if (stream != null)
stream.Close();
if (hrep != null)
hrep.Close();
}
return resultStr;
}
转载于:https://www.cnblogs.com/qinyun118/archive/2010/11/01/1866123.html