获取目标网页的内容

HttpWebRequest request = WebRequest.Create("http://www.1314721.com.cn/") as HttpWebRequest;             HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            if (response.StatusCode == HttpStatusCode.OK)             {                 string characterSet = response.CharacterSet;                 Encoding encode;                 if (characterSet != "")                 {                     encode = Encoding.GetEncoding(characterSet);                 }                 else                 {                     encode = Encoding.Default;                 }

                Stream receiveStream = response.GetResponseStream();                 StreamReader reader = new StreamReader(receiveStream, encode);                 char[] read = new char[255];                 // 每次读取255                 int count = reader.Read(read, 0, 255);                 string str = string.Empty;                 while (count > 0)                 { // 如果读到一定数目的字符串后,将这些字符串输入到string中                     str += new String(read, 0, count);                     count = reader.Read(read, 0, 255); // 再读下面的255内容                 }                 webBrowser1.DocumentText = str;

                // 读取完毕                 reader.Close();                 receiveStream.Close();

本文来自http://www.1314721.com.cn/

获取目标网页的内容,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。