问题描述
我正在使用Jersey客户端访问Web服务,如下所示:response =r.accept(MediaType.TEXT_PLAIN_TYPE).header("content-length", 0).post(String.class);
其中r是WebResource
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
但是,Web服务返回411-缺少内容长度.
However, the Webservice returns 411 - Content-Length is missing.
使用tcpdump,我发现我可以指定自定义标头,即.header("myheader", 0)
可以正常工作.
using tcpdump, i found out that i am able to specify custom headers, i.e. .header("myheader", 0)
works fine.
因此,出于某些原因,球衣似乎正在删除content-length标头.
So it seems that jersey is deleting the content-length header for some reasons.
有人有什么主意吗?
推荐答案
呼叫的内容长度由Jersey Client计算,无法设置.保罗·桑德兹(Paul Sandoz)(该项目的著名提交者)已回答一个类似的问题:
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:
A:泽西岛运行时[...]确定内容的长度.
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.
这篇关于未在Jersey客户请求中设置Content-Length-Header的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!