开发者

How to decompress GZip in Stream (C#)?

开发者 https://www.devze.com 2023-03-17 15:38 出处:网络
This code receives the GZip-encoded string. How can I de开发者_运维知识库code it? Stream stream = ret.GetResponseStream();

This code receives the GZip-encoded string. How can I de开发者_运维知识库code it?

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?


One other way is to use Automatic decompression property of the request/response:

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

Set this property before you get the response.

0

精彩评论

暂无评论...
验证码 换一张
取 消