I am not sure if my question is correct, but I couldn't find any relevant information. I am assuming that HttpClient is supposed to decrypt HTTPS responses automatically, but for some reason, it doesn't, except when the Fiddler is running.
HttpClient Client;
HttpResponseMessage response;
using (var request = new HttpRequestMessage(HttpMethod.Get, "https://www.google.com/"))
{
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));
response = await Client.SendAsync(request);
response.EnsureSuccessStatusCode();
}
string sResponse = await response.Content.ReadAsStringAsync();
Log(sResponse); // "\u001f�\b\0\0\0\0\0\u0002��i{۸�0��\u007f\u0005͜c�c�\u0016" etc.
I tried to disable all https-related options in Fiddler and resetting IE proxy options, but it seems not the case.
It turned out I had the wrong Accept-Encoding header:
Client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
EDIT:
You CAN use "gzip, deflate" encoding, but you have to specify decompression method in your HttpClientHandler:
HttpClientHandler handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
using (var client = new HttpClient(handler))
{
// your code
}