日期:2014-05-18 浏览次数:20422 次
/// <summary> /// 根据Url地址得到网页的html源码 GB2312格式 /// </summary> /// <param name="Url">远程地址</param> /// <returns></returns> public static string GetWebContent(string Url) { string strResult = ""; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); //声明一个HttpWebRequest请求 request.Timeout = 30000; //设置连接超时时间 request.Headers.Set("Pragma", "no-cache"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream streamReceive = response.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("GB2312"); StreamReader streamReader = new StreamReader(streamReceive, encoding); strResult = streamReader.ReadToEnd(); streamReader.Close(); streamReceive.Close(); return strResult; }