0

Recently I have been experimenting with the HttpClient class and I've encountered some odd behavior: HttpClient on .NET Core 1.1 is automatically decompressing response content with gzip and deflate, but HttpClient on .NET Framework 4.6.2 isn't. Here's the code I'm using:

string url = "http://www.youtube.com";

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.TryAddWithoutValidation("accept-encoding", "gzip, deflate");

var response = await client.GetAsync(url);

Console.WriteLine(await response.Content.ReadAsStringAsync());
Console.Read();

If this code is run on .NET Framework, the output is garbled (expected), but if run on .NET Core, the output is readable HTML.

The way I discovered this was including the code above in a .NET standard project, and then referencing it from both a .NET Framework console app and a .NET Core console app.

As far as I can tell, the HttpClient class doesn't have very good documentation in general, so which behavior is correct?

This is a potentially breaking change to .NET Standard libraries, but it doesn't seem like .NET Standard guarantees defaults like this, so is this a bug or minor platform inconsistency?

Thanks

Blue0500
  • 715
  • 8
  • 16
  • Does https://stackoverflow.com/a/27327208/34092 work in both .NET 4.6.2 and Core 1.1? Is there a reason you are wanting the data **not** to be decompressed? – mjwills Jun 21 '17 at 22:41

1 Answers1

0

This was a breaking change from netcoreapp1.1 to netcoreapp2.0...netcoreapp1.1 did not follow the same standards as .NET Framework, but it was fixed in netcoreapp2.0. If you compile against 2.0, you should observe the same behavior between both .NET Core and .NET Framework.

https://github.com/dotnet/corefx/issues/18646#issuecomment-295511967

Arcanox
  • 1,420
  • 11
  • 20