Page 1 of 1

How to decode gzip response

Posted: Fri Jun 14, 2019 1:29 pm
by ScottM
Hopefully I am missing something very simple.

Doing a basic WebClient.DownloadString() call to get a text file. Using Fiddler, it looks like I get a gzip of that text file. Which isn't so very string-like. (Fiddler offers to decode it, and then I can see the return that I want.) In a WPF use of the same code, the string gets returned to me whole, not encoded.

How do I decode it to UTF-8? (Or avoid the gzip?)

I found the ZipFile Extension, but don't see an exposed call there to upzip the return.

Re: How to decode gzip response

Posted: Fri Jun 14, 2019 1:55 pm
by ScottM
Using Fiddler to look at WPF vs. CSHTML5, when I use WPF for the above, I get request headers:

Code: Select all

GET /panthers/Gifting.txt HTTP/1.1
Host: www.musserportal.com
Connection: Keep-Alive

and CSHTML5 I get:

Code: Select all

GET /panthers/Gifting.txt HTTP/1.1
Origin: http://musserportal.com
Referer: http://musserportal.com/salesportal/?panthers
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
Content-Type: text/plain
Accept: */*
Accept-Language: en-US,en;q=0.8,es-ES;q=0.7,es;q=0.5,el;q=0.3,he;q=0.2
Accept-Encoding: gzip, deflate, br
Host: www.musserportal.com
DNT: 1
Connection: Keep-Alive

I tried this:

Code: Select all

WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
webClient.Headers[HttpRequestHeader.Accept] = "";
webClient.Headers[HttpRequestHeader.AcceptEncoding] = "";
webClient.Headers[HttpRequestHeader.ContentType] = "text/plain";

and managed only to turn Accept to empty.

And still got the gzip back.

If I could figure out how to un-gzip that buffer (which I think amounts to using the right unzip code / package), I'd be in business, I think.

Re: How to decode gzip response

Posted: Thu Jun 20, 2019 11:15 am
by ScottM
Bump on this and related question...

I'm trying to use an URL parameter to allow me to re-use the app to customize it for various clients and potential clients (of my client). The file above that I'm trying to read indicates a folder containing the text and graphic files to be used when displaying the app options.

The file that's coming back (I think) compressed (and doesn't in WPF) is just a text file that drives the customization and the use of the other files in that folder.

Per the discussion here on faking navigation between pages using a page control:

viewtopic.php?f=2&t=126&p=10632#p10630

what happens when I use that URL parameter, the links go like this:

Entered: xyz.com/salesportal/?panthers
Displayed: http://xyz.com/salesportal/?panthers#MainPage.xaml
When "Gifting" is clicked and frame navigated: http://xyz.com/salesportal/?panthers#GiftingPage.xaml

Is the embedding of ?parameter before the #(xaml) to be expected like that, and is that likely to behave for me going forward?

Assuming I can get around the compressed return (ideally by not getting a compressed return), I think I am close.

Re: How to decode gzip response

Posted: Mon Jun 24, 2019 5:01 pm
by ScottM
I don't know how or why, but the text files are now coming down unzipped.

I wish I could say I did X, Y or Z to accomplish that.

I was looking at trying to load the pako.min.js script into the page and use it for unzipping. Would that be the right approach?

Re: How to decode gzip response

Posted: Wed Jun 26, 2019 9:42 am
by JS-Support @Userware
ScottM wrote:I was looking at trying to load the pako.min.js script into the page and use it for unzipping. Would that be the right approach?


Yes. You can use the ZipFile Extension as an example of how to use an external JS library to decompress:
http://forums.cshtml5.com/viewtopic.php?f=7&t=521