根据url获取网站HTML内容
/// <summary>
/// 根据url获取网站HTML内容
/// </summary> /// <param name="url">网址</param>
/// <returns>获取网站HTML内容</returns>
public string GetHtmlContentByUrl(string url)
{
var htmlContent = string.Empty;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Timeout = 10000000;
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
var stream = httpWebResponse.GetResponseStream();
if (stream != null)
{
var streamReader = new StreamReader(stream, System.Text.Encoding.UTF8);
htmlContent = streamReader.ReadToEnd();
streamReader.Close();
streamReader.Dispose();
stream.Close();
stream.Dispose();
}
httpWebResponse.Close();
return htmlContent;
}
摘自 期待光明前景
补充:Web开发 , 其他 ,