Last active
July 29, 2021 13:50
-
-
Save jonathanpeppers/553753338ae57d8e706da92ef3813880 to your computer and use it in GitHub Desktop.
HttpClient with GZip
This file contains hidden or 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
var httpClient = new HttpClient(); | |
httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); | |
//Nope, you don't have to even mess with GZipStream | |
string text = await httpClient.GetAsString("http://chucknorris.com"); | |
//NOTE: but if you need this to work on Windows or non-Xamarin platforms, you will need this ctor for HttpClient | |
var httpClient = new HttpClient(new HttpClientHandler | |
{ | |
AutomaticDecompression = DecompressionMethods.GZip, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @jonathanpeppers,
is not working. Always setting Header as:
Accept-Encoding: identity
on Android. iOS not tested.