我遇到了异常,gzip is not support。这就是我用来加载页面的全部内容,关于如何允许 gzip 有什么想法吗?
HtmlWeb hwObject = new HtmlWeb();
HtmlAgilityPack.HtmlDocument htmldocObject = hwObject.Load(siteURL);
您可以自己下载该页面,即使用派生自的类WebClient
(或手动制作WebRequest
和设置AutomaticDecompression
)
public class GZipWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
return request;
}
}
鉴于此你可以这样做:
string html;
using(var wc = new GZipWebClient())
html = wc.DownloadString(siteUrl);
var htmldocObject = new HtmlDocument();
htmldocObject.LoadHtml(html);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)