Skip to content

Instantly share code, notes, and snippets.

@jonathanpeppers
Last active July 29, 2021 13:50
Show Gist options
  • Save jonathanpeppers/553753338ae57d8e706da92ef3813880 to your computer and use it in GitHub Desktop.
Save jonathanpeppers/553753338ae57d8e706da92ef3813880 to your computer and use it in GitHub Desktop.
HttpClient with GZip
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,
});
@AlleSchonWeg
Copy link

AlleSchonWeg commented Jul 29, 2021

Hi @jonathanpeppers,

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));

is not working. Always setting Header as:
Accept-Encoding: identity

on Android. iOS not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment