Retrieve Json data with HttpClient

自作多情 提交于 2019-12-03 13:49:57
svick

The problem is that the response is compressed and HttpClient does not automatically decompress it by default.

With WebClient, you can create a derived class and set the AutomaticDecompression of the underlying HttpWebRequest.

You can't do that with HttpClient, because it doesn't have any suitable virtual methods. But you can do it by passing HttpClientHandler to its constructor:

var client =
    new HttpClient(
        new HttpClientHandler
        {
            AutomaticDecompression = DecompressionMethods.GZip
                                     | DecompressionMethods.Deflate
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!