4

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);

1 Answer 1

12

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);
3
  • thanks for the tip, i was looking for a way to handle this exception though
    – user222427
    Jan 20, 2012 at 2:39
  • last I checked you can either modify the HtmlAgilityPack source code, i.e. see here: htmlagilitypack.codeplex.com/discussions/22790 or need to download the content yourself Jan 20, 2012 at 2:46
  • 1
    @Mike - Grab the source from the repository, make your changes, and compile it yourself.
    – M.Babcock
    Jan 20, 2012 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.