本文介绍了htmlagilitypack gzip的加密例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有例外抛出的gzip不支持。这是所有我使用的加载页面,如何让gzip的任何想法?
HtmlWeb hwObject =新HtmlWeb( );
HtmlAgilityPack.HtmlDocument htmldocObject = hwObject.Load(SITEURL);
解决方案
您可以下载使用类自己的网页,即从派生的WebClient
(或手工制作的WebRequest
并设置 AutomaticDecompression
)
公共类GZipWebClient:Web客户端
{
保护覆盖的WebRequest GetWebRequest(URI地址)
{
HttpWebRequest的要求=(HttpWebRequest的)base.GetWebRequest(地址);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
退货要求;
}
}
鉴于这一点,你可以这样做:
字符串的html;使用(VAR WC =新GZipWebClient())
HTML = wc.DownloadString(SITEURL)
;
变种htmldocObject =新的HTMLDocument();
htmldocObject.LoadHtml(HTML);
I'm having the exception throw gzip is not support. This is all i'm using the load the page, any idea on how to allow gzip?
HtmlWeb hwObject = new HtmlWeb();
HtmlAgilityPack.HtmlDocument htmldocObject = hwObject.Load(siteURL);
解决方案
You can download the page yourself, i.e. using a class derived from WebClient
(or manually making a WebRequest
and setting 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;
}
}
Given this you can do:
string html;
using(var wc = new GZipWebClient())
html = wc.DownloadString(siteUrl);
var htmldocObject = new HtmlDocument();
htmldocObject.LoadHtml(html);
这篇关于htmlagilitypack gzip的加密例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!