-1

In HTTP request and response, content-encoding is 'gzip' and content is gzipped. Is there a way to decompress the gzipped content so we can see the contents ??

Example for GZipped HTTP request

HTTP/1.1 200 OK
Date: mon, 15 Jul 2014 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix)  (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip

//Response body with non type characters
Pasupathi Rajamanickam
  • 1,982
  • 1
  • 24
  • 48

2 Answers2

0

That shouldn't be necessary. Your application server should handle such requests for you and decompress the payload for you automatically.

If that doesn't happen, you need to wrap the InputStream in a GZipInputStream. But this sounds more like a misconfiguration of your server.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0

Found the answer.

//reply - Response from Http  byte[] reply = getResponseBytes();
 int i;
             for(i=0;i<reply.length;i++){
              //Finding Raw Response by two new line bytes
                 if(reply[i]==13){
                     if(reply[i+1]==10){
                         if(reply[i+2]==13){
                             if(reply[i+3]==10){
                                 break;
                             }
                         }
                     }
                 }

             }
             //Creating new Bytes to parse it in GZIPInputStream  
             byte[] newb = new byte[4096];
             int y=0;
             for(int st=i+4;st<reply.length;st++){
                 newb[y++]=reply[st];
             }
                       GZIPInputStream  gzip = new GZIPInputStream (new ByteArrayInputStream (newb));
                        InputStreamReader reader = new InputStreamReader(gzip);
                        BufferedReader in = new BufferedReader(reader);

                        String readed;
                        while ((readed = in.readLine()) != null) {
                            //Bingo...
                            System.out.println(readed);
                        }
Pasupathi Rajamanickam
  • 1,982
  • 1
  • 24
  • 48