Gzipstream使用中出现问题,GZip 头中的幻数不正确。附源码。

NeverFear 2018-03-26 01:23:28
我写了一个使用xNet抓取的小程序,显示“GZip 头中的幻数不正确”,请大虾帮忙看看是什么问题。

源码下载:https://pan.baidu.com/s/1p52QLmWAB-1eqwqYB1Xk3A
...全文
733 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanta 2018-03-27
  • 打赏
  • 举报
回复
幻数不正确,说明这个文件不是zip文件,最好检查下文件。
xuzuning 2018-03-26
  • 打赏
  • 举报
回复
网站嘛还不好骗,只要你谎称不支持 gzip 他就不压缩了
「已注销」 2018-03-26
  • 打赏
  • 举报
回复
引用 8 楼 xuzuning 的回复:
如果目标 url 就是你代码中的那个,返回的 http 头只有这几项 [0] => HTTP/1.1 302 Moved Temporarily [1] => Content-Type: text/html; charset=UTF-8 [2] => Location: http://www.fhxiaoshuo.com/read/100/100447/ [3] => Server: Microsoft-IIS/7.5 [4] => X-Powered-By: PHP/5.2.17 [5] => Set-Cookie: jieqiVisitTime=jieqiArticlesearchTime%3D1522043465; expires=Mon, 26-Mar-2018 06:51:05 GMT; path=/ [6] => X-Powered-By: ASP.NET [7] => Date: Mon, 26 Mar 2018 05:51:05 GMT [8] => Connection: close [9] => Content-Length: 165 [10] => HTTP/1.1 200 OK [11] => Content-Type: text/html [12] => Server: Microsoft-IIS/7.5 [13] => Date: Mon, 26 Mar 2018 05:47:13 GMT [14] => X-Via: 341-282-299-802-792 Fikker/Webcache/3.6.1 [15] => Content-Length: 90905 [16] => Connection: close 并无 gzip 字样 除非俄国佬显式的请求了 gzip 方式(没去看细节) 但这样不加验证的,就有点草率了 至少应判断一下流的头两个字节是 0x1f 0x8b 吧
我用Chrome看到的是这样子的。 Request URL: http://www.fhxiaoshuo.com/read/100/100447/ Request Method: GET Status Code: 200 OK Remote Address: 103.50.88.248:80 Referrer Policy: no-referrer-when-downgrade Content-Encoding: gzip Content-Length: 21398 Content-Type: text/html Date: Mon, 26 Mar 2018 06:38:05 GMT Server: Microsoft-IIS/7.5 Vary: Accept-Encoding X-Powered-By: ASP.NET Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 Cache-Control: max-age=0 Connection: keep-alive Host: www.fhxiaoshuo.com Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
xuzuning 2018-03-26
  • 打赏
  • 举报
回复
如果目标 url 就是你代码中的那个,返回的 http 头只有这几项
[0] => HTTP/1.1 302 Moved Temporarily
[1] => Content-Type: text/html; charset=UTF-8
[2] => Location: http://www.fhxiaoshuo.com/read/100/100447/
[3] => Server: Microsoft-IIS/7.5
[4] => X-Powered-By: PHP/5.2.17
[5] => Set-Cookie: jieqiVisitTime=jieqiArticlesearchTime%3D1522043465; expires=Mon, 26-Mar-2018 06:51:05 GMT; path=/
[6] => X-Powered-By: ASP.NET
[7] => Date: Mon, 26 Mar 2018 05:51:05 GMT
[8] => Connection: close
[9] => Content-Length: 165
[10] => HTTP/1.1 200 OK
[11] => Content-Type: text/html
[12] => Server: Microsoft-IIS/7.5
[13] => Date: Mon, 26 Mar 2018 05:47:13 GMT
[14] => X-Via: 341-282-299-802-792 Fikker/Webcache/3.6.1
[15] => Content-Length: 90905
[16] => Connection: close
并无 gzip 字样
除非俄国佬显式的请求了 gzip 方式(没去看细节)

但这样不加验证的,就有点草率了
至少应判断一下流的头两个字节是 0x1f 0x8b 吧
「已注销」 2018-03-26
  • 打赏
  • 举报
回复
引用 6 楼 xuzuning 的回复:
凤凰小说网 ? 并没有 gzip 压缩,你也硬去解压?
headerj里边是有gzip呀。
xuzuning 2018-03-26
  • 打赏
  • 举报
回复
凤凰小说网 ? 并没有 gzip 压缩,你也硬去解压?
「已注销」 2018-03-26
  • 打赏
  • 举报
回复
https://download.csdn.net/download/neverfear/10308892 我把源码传到csdn的下载里边了,不过最少资源分都必须设置为2分。。。。。不好意思了。
  • 打赏
  • 举报
回复
你先发发截图什么的吧,下载你的代码运行有点困难。
「已注销」 2018-03-26
  • 打赏
  • 举报
回复
引用 3 楼 xomix 的回复:
你先发发截图什么的吧,下载你的代码运行有点困难。
System.IO.InvalidDataException: GZip 头中的幻数不正确。请确保正在传入 GZip 流。
   在 System.IO.Compression.GZipDecoder.ReadHeader(InputBuffer input)
   在 System.IO.Compression.Inflater.Decode()
   在 System.IO.Compression.Inflater.Inflate(Byte[] bytes, Int32 offset, Int32 length)
   在 System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count)
   在 System.IO.Compression.GZipStream.Read(Byte[] array, Int32 offset, Int32 count)
   在 xNet.HttpResponse.<ReceiveMessageBodyZip>d__101.MoveNext() 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpResponse.cs:行号 1476
   在 xNet.HttpResponse.None() 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpResponse.cs:行号 847
   在 xNet.HttpRequest.CloseConnectionIfNeeded() 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpRequest.cs:行号 2317
   在 xNet.HttpRequest.Request(HttpMethod method, Uri address, HttpContent content) 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpRequest.cs:行号 2217
   在 xNet.HttpRequest.Request(HttpMethod method, Uri address, HttpContent content) 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpRequest.cs:行号 2298
   在 xNet.HttpRequest.Raw(HttpMethod method, Uri address, HttpContent content) 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpRequest.cs:行号 1538
   在 xNet.HttpRequest.Raw(HttpMethod method, String address, HttpContent content) 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpRequest.cs:行号 1490
   在 xNet.HttpRequest.Get(String address, RequestParams urlParams) 位置 C:\Users\maste\source\repos\WindowsFormsApp1\xNet-master\xNet\~Http\HttpRequest.cs:行号 935
   在 WindowsFormsApp1.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Users\maste\Desktop\WindowsFormsApp1\WindowsFormsApp1\Form1.cs:行号 29
出错trace
「已注销」 2018-03-26
  • 打赏
  • 举报
回复
引用 1 楼 xomix 的回复:
https://bbs.csdn.net/topics/330030312
我看过那个帖子。没有帮助啊,只能重新发帖了。
  • 打赏
  • 举报
回复
https://bbs.csdn.net/topics/330030312

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧