Decompress a GZipped response from the server (Socket)

Posted by Lith on Stack Overflow See other posts from Stack Overflow or by Lith
Published on 2010-04-11T23:06:35Z Indexed on 2010/04/11 23:13 UTC
Read the original article Hit count: 218

Filed under:

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

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

I am getting the following response:

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.

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 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 >__>.

© Stack Overflow or respective owner

Related posts about c#3.0