如何在WinRT中解压缩GZipped HTTP响应

时间:2015-01-05 22:58:41

标签: c# http windows-runtime httpwebrequest gzip

在通常的.NET环境中,我们在类HttpWebRequest中有一个属性AutomaticDecompression。

httpRequest.AutomaticDecompression = 
    (DecompressionMethods.GZip | DecompressionMethods.Deflate);

问题是我在WinRT上,而且HttpWebRequest类中没有这样的属性。我有什么?我有GZip压缩的响应流......

1 个答案:

答案 0 :(得分:1)

使用HttpClientHandler,因为它支持AutomaticDecompression:

System.Net.Http.HttpClientHandler hc = new System.Net.Http.HttpClientHandler();
hc.AutomaticDecompression = System.Net.DecompressionMethods.GZip;

System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(hc);

var result = await client.GetAsync(uri)