欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

http gzip 解压缩

程序员文章站 2024-03-14 09:18:06
...
          var sContentEncoding = httpRespone.Headers["Content-Encoding"];
                
                if(sContentEncoding == "gzip")
                {
		    
                    MemoryStream msTemp = new MemoryStream();

                    int count = 0;
                    GZipStream gzip = new GZipStream(httpRespone.GetResponseStream(), CompressionMode.Decompress);
                    byte[] buf = new byte[1000];
                    byte[] byteArray = null;

                    while((count = gzip.Read(buf,0,buf.Length)) > 0)
                  {     
                           msTemp.Write(buf,0,count);
                    }
                    byteArray = msTemp.ToArray();
		    
                    string sHtml = Encoding.UTF8.GetString(byteArray);

                }