Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest and gzip

Do I need to specify in my request that I wish to accept gzip, or is this default behavior? I am talking to a WCF RESTful Json service.

// Create the web request  
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

request.Headers["Accept-Encoding"] = "gzip";
like image 437
Ian Vink Avatar asked Aug 12 '11 18:08

Ian Vink


1 Answers

Actually, you should just set AutomaticDecompression, the WebRequest will set Accept-Encoding for you automatically.

request.AutomaticDecompression = DecompressionMethods.GZip
like image 186
Paul Jackson Avatar answered Nov 06 '22 03:11

Paul Jackson