日期:2014-05-17  浏览次数:20446 次

C# gzip 解压 问题
最近公司 要做一个接口,不过对方放回的 是通过gzip 加压过的,现在我只能得到乱码的字符串,请问如果讲 gzip 解压 成 原来的 字符串

------解决方案--------------------
http://stackoverflow.com/questions/1581694/gzipstream-and-decompression
------解决方案--------------------

if (HttpWResp.ContentEncoding.ToLower().Contains("gzip"))
            {
                using (GZipStream stream = new GZipStream(HttpWResp.GetResponseStream(), CompressionMode.Decompress))
                {
                    using (reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("gb2312")))
                    {
                        result = reader.ReadToEnd();
                        //return HttpUtility.HtmlDecode(result);
                    }
                }
            }
            else
            {
                Stream myStream = HttpWResp.GetResponseStream();
                using (reader = new StreamReader(myStream, System.Text.Encoding.GetEncoding("gb2312")))
                {
                    result = reader.ReadToEnd();
                }
            }


先判断http请求返回的头里面是否gzip 标志  用相应的方法获取其内容
------解决方案--------------------
http://download.csdn.net/detail/gcm3206021155665/3014624