File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Apache Http Client Request Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Apache Http Client Request Header" Watch "Apache Http Client Request Header" New topic
Author

Apache Http Client Request Header

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

I'm trying to make an Http Post request call to a Http server. I'm using the Apache Http Client library to write the client that connects to the server:



The call reaches the server, but surprisingly I'm facing two issues:

1. the header that I set, Content-Encoding is missing when the request arrives at the server.

Here is what I see as part of the request headers on the server:

Map(Charset -> UTF-8, Connection -> Keep-Alive, Content-Length -> 5530, Content-Type -> application/octet-stream, User-Agent -> Apache-HttpClient/4.1.1 (java 1.5), Host -> MyComputer:9000)

2. It fails when trying to unzip the contents using Gunzip utility that I have on the server.

Any ideas?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
Using GZIP for transfer compression isn't achieved by just setting that header, nor -would I imagine- would it be easy to get at the gzipped data on the server (because it's automatically ungzipped).

See the "Custom protocol interceptors" example at http://hc.apache.org/httpcomponents-client-4.2.x/examples.html


Ping & DNS - my free Android networking tools app
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

Here is the getBytePaylod method that does the GZip compression on the client!



I noticed that on the server, the length of the content is 5330 equal to the uncompressed file size. The server now fails wiht the exception saying that the input fed is not a GZIP file:



I traced it back to the source code on the server where the error on the server is thrown. Here is a code snippet of that. It fails saying that the Gzip Magic number is missing?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
Have you used a network monitor to ascertain whether or not the content *is* gzipped in transfer?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

Ulf Dittmer wrote:Have you used a network monitor to ascertain whether or not the content *is* gzipped in transfer?


I have not tried that. How could I do that? Right now, I'm running the client from within intelliJ!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
WireShark is a good one.
 
 
subject: Apache Http Client Request Header