0

In usual .NET environment we have a property AutomaticDecompression in class HttpWebRequest.

httpRequest.AutomaticDecompression = 
    (DecompressionMethods.GZip | DecompressionMethods.Deflate);

Problem is that i am on WinRT, and here is no such property in HttpWebRequest class. And what i have? I have GZip-compressed response stream...

Croll
  • 3,631
  • 6
  • 30
  • 63

1 Answers1

1

Use the HttpClientHandler, as it supports the AutomaticDecompression:

System.Net.Http.HttpClientHandler hc = new System.Net.Http.HttpClientHandler();
hc.AutomaticDecompression = System.Net.DecompressionMethods.GZip;

System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(hc);

var result = await client.GetAsync(uri)
John Koerner
  • 37,428
  • 8
  • 84
  • 134
  • You can do that with the Client and the ClientHandler: [Timeout](http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout%28v=vs.118%29.aspx) [Headers](http://stackoverflow.com/questions/12022965/adding-http-headers-to-httpclient-asp-net-web-api) [Allow AutoRedirect](http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.allowautoredirect%28v=vs.118%29.aspx) – John Koerner Jan 06 '15 at 00:01
  • There is no System.Net.Http at all in portable library framework. Unsolved – Croll Jan 07 '15 at 21:21
  • This code works perfectly fine for me in a WindowsRuntimeComponent library. – John Koerner Jan 07 '15 at 21:35
  • @Croll docs say HttpClient is available in portable .Net platforms https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx – Max Barraclough Jul 23 '18 at 11:25