此代码接收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?
另一种方法是使用请求/响应的自动解压缩属性:
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
在获得响应之前设置此属性。