Adding automatic decompression support to an HttpClient is quite easy:
var handler = new HttpClientHandler();
if (handler.SupportsAutomaticDecompression)
{
handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
}
var httpClient = new HttpClient(handler);
This works even in Portable Libraries. However, if you try to call this from a different project, you might encounter the strange exception below:
Method not found:
void System.Net.Http.HttpClientHandler.set_AutomaticDecompression(System.Net.DecompressionMethods)
.
This doesn’t give too much information – for some reason, the setter of the AutomaticDecompression
property was not found, which prevents the code from JIT’ing. Apparently, the solution for that is quite simple – you need to make sure that the project that calls the Portable Library also refers to the Microsoft.Net.Http Nuget package.