【问题标题】:How to decompress GZipped HTTP response in WinRT如何在 WinRT 中解压缩 GZipped HTTP 响应
【发布时间】:2015-01-05 22:58:41
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# http windows-runtime httpwebrequest gzip


    【解决方案1】:

    使用HttpClientHandler,因为它支持自动解压:

    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)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多