码迷,mamicode.com
首页 > Web开发 > 详细

获取目标网页的内容

时间:2014-07-19 14:25:36      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:http   os   re   c   ar   new   

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/

获取目标网页的内容,布布扣,bubuko.com

获取目标网页的内容

标签:http   os   re   c   ar   new   

原文地址:http://www.cnblogs.com/tongzhuancc/p/3854589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!