首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

为何不能完整读取网页数据,该如何处理

2012-06-17 
为何不能完整读取网页数据WebClient MyWebClient new WebClient()string html MyWebClient.DownloadS

为何不能完整读取网页数据

WebClient MyWebClient = new WebClient(); 
string html = MyWebClient.DownloadString("http://bbs.dahe.cn/bbs/thread-1647174-2498-1.html");

为何 读出来的数据 不完整啊?(读出的只有大概 不到64K 的数据)你可直接打开网页,查看源文件,可看出数据量不一样
------------------------------
当然,若网页数据量不大时,读取是没问题的

大家碰到过这种情况吗?如何解决?谢谢啦!


[解决办法]

C# code
WebClient MyWebClient = new WebClient();MyWebClient.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";string html = MyWebClient.DownloadString("http://bbs.dahe.cn/bbs/thread-1647174-2498-1.html");
[解决办法]
压缩的可使用
System.IO.Compression.DeflateStream responseStream =new System.IO.Compression.DeflateStream( httpWebResponse.GetResponseStream(),System.IO.Compression.CompressionMode.Decompress);

热点排行