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/
原文地址:http://www.cnblogs.com/tongzhuancc/p/3854589.html