目录
当你处理http时,返回的html的header中包含:
Content-Encoding: deflate
或
Content-Encoding: gzip
时,说明是返回的是压缩的HTML。
想要支持压缩的html的话,C#中,在发送HttpWebRequest之前,设置AutomaticDecompression为对应的参数即可:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); ...... req.Headers["Accept-Encoding"] = "gzip, deflate"; //req.AutomaticDecompression = DecompressionMethods.GZip; req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
更多解释详见:
示例代码:
using System.Net; WebProxy gProxy = new WebProxy("127.0.0.1", 8087); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Proxy = gProxy;
在用C#的GetResponseStream,常会遇到,ReadLine或ReadToEnd会无限期挂掉,所以,需要去加上对应的超时(timeout)设置: