Does .NET's HttpWebResponse uncompress automatically GZiped and Deflated responses?

Jader Dias picture Jader Dias · Mar 24, 2009 · Viewed 21k times · Source

I am trying to do a request that accepts a compressed response

var request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");

I wonder if when I add the second line I will have to handle the decompression manually.

Answer

Jader Dias picture Jader Dias · Mar 24, 2009

I found the answer.

You can change the code to:

var request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

And you will have automatic decompression. No need to change the rest of the code.