2016-09-15 70 views
0

我不確定我的問題是否正確,但我找不到任何相關信息。我假設HttpClient應該自動解密HTTPS響應,但出於某種原因,它不會,除非Fiddler正在運行。HttpClient不解密沒有Fiddler的HTTPS

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. 

我試圖禁用Fiddler中的所有https相關選項並重置IE代理選項,但似乎並非如此。

回答

0

原來我錯了Accept-Encoding頭:

Client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate"); 

編輯:

你可以使用 「的gzip,緊縮」 編碼,但你必須在指定的減壓方法你HttpClientHandler

HttpClientHandler handler = new HttpClientHandler() 
{ 
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate 
}; 

using (var client = new HttpClient(handler)) 
{ 
    // your code 
}