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