【问题标题】:How to decompress GZip in Stream (C#)?如何在 Stream (C#) 中解压 GZip?
【发布时间】:2011-07-04 08:24:33
【问题描述】:

此代码接收 GZip 编码的字符串。如何解码?

Stream stream = ret.GetResponseStream();

System.IO.StreamReader reader = new System.IO.StreamReader(stream, Encoding.Default);

string answer = reader.ReadToEnd();//answer is GZip encoded string !

byte[] bytes = Encoding.Default.GetBytes(answer);

//???

GZipStream compStream = new GZipStream(stream, CompressionMode.Decompress);

// ... what's next?

【问题讨论】:

    标签: c# stream gzip gzipstream


    【解决方案1】:

    另一种方法是使用请求/响应的自动解压属性:

    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
    

    在收到响应之前设置此属性。

    【讨论】:

    • 太远了,这让事情变得简单多了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 2014-10-21
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多