Skip to content

Instantly share code, notes, and snippets.

@DannySotzny
Created January 27, 2016 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannySotzny/bae19529c04641fa308b to your computer and use it in GitHub Desktop.
Save DannySotzny/bae19529c04641fa308b to your computer and use it in GitHub Desktop.
C#: Enable Automatic Decompression on System.Net.WebClient
public class AutomaticDecompressionWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address) as HttpWebRequest;
if (request == null) throw new InvalidOperationException("You cannot use this WebClient implementation with an address that is not an http uri.");
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
return request;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment