C#使用Gzip解压缩完整读取网页内容
- using System;
- using System.Threading;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.IO.Compression;
- using System.IO;
- using System.Web;
- using System.Net;
- class Test
- {
- static void Main()
- {
- string url = "http://www.cnblogs.com/waw/";
- getHtml1(url);
- getHtml2(url);
- Console.ReadKey();
- }
- private static void getHtml1(string url)
- {
- StringBuilder s = new StringBuilder();
- WebClient wr = new WebClient();
- wr.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
- byte[] buffer = wr.DownloadData(url);
- GZipStream g = new GZipStream((Stream)(new MemoryStream(buffer)), CompressionMode.Decompress);
- byte[] d = new byte[];
- int l = g.Read(d, , );
- while (l > )
- {
- s.Append(Encoding.Default.GetString(d, , l));
- l = g.Read(d, , );
- }
- Console.Write(s.ToString() + "/n/n/n" + s.Length);
- }
- private static void getHtml2(string url)
- {
- StringBuilder s = new StringBuilder();
- HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
- wr.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
- HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
- head(response);
- GZipStream g = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
- byte[] d = new byte[];
- int l = g.Read(d, , );
- while (l > )
- {
- s.Append(Encoding.Default.GetString(d, , l));
- l = g.Read(d, , );
- }
- Console.Write(s.ToString() + "/n/n/n" + s.Length);
- }
- private static void head(HttpWebResponse r)
- {
- string[] keys = r.Headers.AllKeys;
- for (int i = ; i < keys.Length; ++i)
- {
- Console.WriteLine(keys[i] + " " + r.Headers[keys[i]]);
- }
- }
- }
C#使用Gzip解压缩完整读取网页内容的更多相关文章
- Windows API方式直接调用C#的DLL,支持多音字转拼音、Gzip解压缩、公式计算(VBA、C++、VB、Delphi甚至java都可以)
原始链接 https://www.cnblogs.com/Charltsing/p/DllExport.html 这两年,我在VBA应用方面一直有几大痛点:1.多音字转拼音:2.64位下的GZIP解压 ...
- excel保存为制表符分隔的文本文件 js无法完整读取
excel保存为制表符分隔的文本文件 js无法完整读取 excel另存为文本有两个选项,一个是制表符分隔的文本文件,一个是unicode文本.生成的文件Unicode更大一些.但是这里需要注意的是[制 ...
- linux串口通信 接收信息不完整 读取不全
类似这种 ready.o是我用来读取串口信息的一个程序 执行结果如下: [root@localhost testPlc]# ./ready.o 0 02 1 30 2 30 3 46 4 46 5 3 ...
- c# gzip解压缩
, bytes.Length)) > ) { line = System.Text.Encoding.Defaul ...
- VB6之借助zlib实现gzip解压缩
这是个简版的,可以拿来做下网页gzip的解压缩,整好我的webserver还不支持这个,有时间了就加上. zlib.dll下载请点击我! 模块zlib.bas的代码如下: 'code by lichm ...
- http gzip 解压缩
var sContentEncoding = httpRespone.Headers["Content-Encoding"]; if(sContentEncoding == &qu ...
- c语言使用zlib实现文本字符的gzip压缩与gzip解压缩
网络上找到的好多方法在解压缩字符串的时候会丢失字符,这里是解决方法: http://stackoverflow.com/questions/21186535/compressing-decompres ...
- AXIS2调用web service,返回结果用GZIP解压缩
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOExceptio ...
- 不能完整读取txt文件问题
txt文件内容 5 1.3 0.4 3.4 -1.7 16.7 0.89 14.17 4.8 1.34 0.42 3.36 -2 16.2 0.9 14.8 4.9 1.30 0.37 3.51 -1 ...
随机推荐
- brew 接口的原理
请查看相关文档的第9章 该文档可以csdn silentjesse帐号下的资源去下载 http://download.csdn.net/detail/silentjesse/5859077
- [Scikit-learn] *Dynamic Bayesian Network - Partical Filter
涉及的一些知识: 机器人的自我定位 Sequential Importance Sampling Ref: http://scipy-cookbook.readthedocs.io/items/Par ...
- 第五章 面向方面编程___AOP入门
上一篇讲了 AOP 和 OOP 的区别,这一次我们开始入门 AOP .实现面向方面编程的技术,主要分为两大类: 一是 采用动态代理技术,利用截取消息的方式,对该消息进行装饰,以取代原有对象行为的执行: ...
- Strut2------源码下载
转载: http://download.csdn.net/detail/dingkui/6858009
- PHP-005
MySql 表列默认时间类型设置:数据类型:timestamp,缺省值:CURRENT_TIMESTAMP
- 简单易懂的snmpd.conf配置文件说明
转自http://blog.chinaunix.net/u2/61187/showart_689604.html 用 snmp+mrtg 可以很好的实现对局域网内服务器状态的监控. 现在就以 ...
- apache 图片防盗链
RewriteEngine on RewriteCond %{HTTP_REFERER} !ot.com [NC] RewriteCond %{HTTP_REFERER} !baidu.com [NC ...
- chmod 777 修改权限
http://william71.blogbus.com/logs/33484772.html 在Unix和Linux的各种操作系统下,每个文件(文件夹也被看作是文件)都按读.写.运行设定权限.例如我 ...
- hadoop错误各种原因
NoRouteToHostException 错误描述: INFO hdfs.DFSClient: Exception in createBlockOutputStream java.net.NoRo ...
- AndroidのListView之滑动列表项(点击事件和滑动事件共存)
这里正好在项目有这么一个bt的需求,如下图ListView的item可以响应点击事件也可以响应item的左右滑动事件,两个事件可以相互独立互不影响. 听说iphone的list选项就有这样bt的功能, ...