Reputation: 273
I'm using Jersey Client to access a webservice, like this:
response =
r.accept(MediaType.TEXT_PLAIN_TYPE).header("content-length", 0).post(String.class);
where r is a WebResource
However, the Webservice returns 411 - Content-Length is missing.
using tcpdump, i found out that i am able to specify custom headers, i.e. .header("myheader", 0)
works fine.
So it seems that jersey is deleting the content-length header for some reasons.
Anyone has any ideas?
Upvotes: 8
Views: 10432
Reputation: 81
I actually had a requirement to use an empty POST request for a Restful webservice.
If you specify an empty string as the second parameter of post method, Jersey will create the Content-Length header with the value of 0.
e.g.
response = r.accept(MediaType.TEXT_PLAIN_TYPE).post(String.class, "");
Upvotes: 8
Reputation: 7244
The content length of a call is computed by Jersey Client, it cannot be set. Paul Sandoz — a well known commiter on the project — have answered a similar question:
Q: I think that "Content-Length" header is not being set automatically.
A: The Jersey runtime [...] determine the length of content.
If you need further informations, please explain what result did you expect from POSTing a String to a Resource with an empty size.
Upvotes: 4