Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apache Http Client Request Header

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you used a network monitor to ascertain whether or not the content *is* gzipped in transfer?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WireShark is a good one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic