解压缩来自服务器(套接字)的GZipped响应 [英] Decompress a GZipped response from the server (Socket)

查看:123
本文介绍了解压缩来自服务器(套接字)的GZipped响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,好了,在向服务器发送了一些数据之后,注意到了这个特殊的部分:

Umm, ok, after sending some data to the server, noting this particular part:

"Accept-Encoding: gzip,deflate\r\n"

我得到以下响应:

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 09 Apr 2010 23:25:27 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.2.8
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Fri, 09 Apr 2010 23:25:27 GMT
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding

7aa
??U-?Rh?%?2?w??PM]??7?qZ?K?)???2?&??m???"q??/p9w?????x?[`tA!G???G?5z??????a>k????????Q
???N??
('??f?,(??Y:5B???-?)?3x^0e:j?`,???**???F>G)?2????@???b??????A?k???Ar?n?

但是如何解压缩呢?我正在使用套接字类来完成所有工作。

But how do I decompress it? Note that I am using the Socket Class to do all the work.

我知道如何解压缩它,但是这里的问题在于我无法将Packet与GZipped数据,伪代码-伪代码(或其他任何有关我的操作方法):

I know how to decompress it, but the problem here lies in the fact that I cannot separate the Packet from the GZipped data, psuedo-psuedocode (or whatever) on how I do it:

Socket sends packet;
Socket reads response from server, stores into a ByteArray;
Create MemoryStream, use ByteArray;
Create GZipStream, use Memorystream;

现在出现了问题;我收到以下错误:

now the problem occurs; I am getting the following Error:


System.IO.InvalidDataException
GZip中的幻数标头不正确
。确保您传递的是
a GZip流。

System.IO.InvalidDataException The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.

我希望解释足够清楚> __>。

I hope the explanation is clear enough >__>.

推荐答案

您需要gzip的内容在双换行符之后开始,并以Content-Length字节为准(如果存在)。您可能会从这里开始。

The content that you need to gzip begins after a double-newline, and goes for (if present) Content-Length bytes. You might start there.

是否可以使用 System.Web.HttpRequest

还是您必须使用原始套接字?

Or do you have to use raw Sockets?

这篇关于解压缩来自服务器(套接字)的GZipped响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆