Skip to content
dotMorten edited this page Feb 22, 2012 · 4 revisions

To add gzip compression to your existing WebClient, simply change your old code:
WebClient myClient = new WebClient();
to:
WebClient myClient = new SharpGIS.GZipWebClient();

That's it! The rest of your code is the same!

If you don't want to change all your code (or your 3rd party libraries that uses WebClient), you can add the following two lines of code, which will force ALL web requests to go through the GZipWebClient without any other changes required. Add the following two lines in your application startup code:
WebRequest.RegisterPrefix("http://", MyWebRequestCreator.MyHttp); WebRequest.RegisterPrefix("https://", MyWebRequestCreator.MyHttp);

NOTE: There are some libraries (like RestSharp) that uses properties on the internal webrequests that can't be overridden, and they will therefore throw an exception. You can change the prefix above to be more specific to certain domains, and limit its impact. Example (only affects requests to github.com):
WebRequest.RegisterPrefix("http://github.com", MyWebRequestCreator.MyHttp);

Clone this wiki locally