1、通过socket页面请求后的receive内容不能经过string后再进行解压缩处理 会造成错误的gzip幻数报错

      推荐使用流处理

2、正确分析返回内容 分割header和页面代码部分

3、对页面代码部分进行解压缩

4、重组header与解压缩后的页面代码

 

解压缩使用net2.0的GZipStream类 很方便

 

     public static string DecompressGzip(Stream stm)
        {
            string strHTML = "";
          
           
            GZipStream gzip = new GZipStream(stm, CompressionMode.Decompress);//解压缩
            using (StreamReader reader = new StreamReader(gzip, Encoding.GetEncoding("gb2312")))//中文编码处理
            {
                strHTML = reader.ReadToEnd();
            }
            
            return strHTML;
        }

 

有些页面请求需要加 Accept-Encoding: gzip, deflate

相关文章:

  • 2021-09-19
  • 2021-06-11
  • 2022-12-23
  • 2021-09-27
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-01
  • 2021-11-28
  • 2021-09-23
相关资源
相似解决方案