Created
January 27, 2016 10:46
-
-
Save DannySotzny/bae19529c04641fa308b to your computer and use it in GitHub Desktop.
C#: Enable Automatic Decompression on System.Net.WebClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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