Archived Forum Post

Index of archived forum posts

Question:

How do we deal with htmls that are Content-Encoding: deflate when using QuickGetStr(url)?

May 06 '14 at 10:55

When I set up my Chilkat http as the following


string url = "http://www.yellowbook.com/profile/hard-rock-cafe_1614116263.html";

Chilkat.Http httpX = new Chilkat.Http();

if (!httpX.IsUnlocked()) httpX.UnlockComponent("XXX");

httpX.AddQuickHeader("Accept-Encoding", "gzip, deflate");

httpX.AllowGzip = true;

httpX.AutoAddHostHeader = true;

string html = httpX.QuickGetStr(url);


I'm get deflated html that looks like this:

I%&/m{JJt$ؐ@iG#)eVe]f@흼{{;N'?fdlJɞ!?~|?"~˓7t.WOm߽{'w>}4x'}Sg˦hjw(h޶Gw^]]Ww.^_[}tD]s,gÇGi-/>(_n#yt> g|RUojqwog@Q)=y6hY=K_UӷIvҗE6u}1ߏӟI˲w-"oXlh]~IXem1)ileGg.n|Do^/.hsNYg|ࣴn->I6eUVeu=+jzmZgt^}t<c磴%ev՛ޤg'_eo_y _="">}|7gO w~`|>ک~^Edo^!S<.8޾]? كf6΄RLfٻݦ.f]~Ջo>?}Ͳ3iwrnZ4a664<du@YCZ,Q-=y-CȦm:#pE٤Uyv!qYWi6m΋&b7i7ӺX <Qv@Wuu^IH.f5!=%Owww?X d-%QtL# (n?xr1z# dqMgU͛דmzꩠZ4SљSy<iEUi颪('=OC3J3)7w


I would like to know what is the correct way to managing html that are deflated.. does Chilkat do this for us, if yes what is the proper set up to do this?

or do I have to write an additional function that will decompress the deflated html from link of interest such as below:

http://www.know24.net/blog/Decompress+GZip+Deflate+HTTP+Responses.aspx

http://weblog.west-wind.com/posts/2012/Apr/28/GZipDeflate-Compression-in-ASPNET-MVC

I was under the impression that we need this line:

httpX.AddQuickHeader("Accept-Encoding", "gzip, deflate");

to be able to read deflated htmls as text.


Answer

When you include Zip and/or Deflate in the Accept-Encodings header, you are just telling the server that you can accept the returned data in those encodings. The server will decide whether it can return the data in either of those formats, and choose one that is appropriate.

It doesn't look like ChilkatHttp has any method to automatically handle Deflate encoding for you (although it can apparently handle gzip encoding via the AllowGzip property). In the case of the YellowBook server, it doesn't have Gzip support, only Deflate (or of course uncompressed/entity encoding). Since you are telling the server you support Deflate encoding, it is returning a deflate encoded string. I think you will need to inflate the results yourself, or omit "deflate" in your Accept-Encoding header (in which case the server will return uncompressed text).


Answer

Chilkat will add support for "deflate" soon. For now, just tell the server you don't want "deflate" as jpbro suggested.

By the way.. gzip uses the deflate algorithm. In essence, the only difference between gzip and deflate is that gzip includes a small header prior to the deflated data. Other than this, the compression is identical.