我们使用cxf jax-rs客户端执行对聚会的请求。请求主体是空的。一个简单的请求调用导致用代码411的服务器响应。
Response-Code: 411
"Content-Length is missing"
我们党的休息器需要设置内容长度的http-header。
我们根据有关块的注释关闭了大块,但这并不能解决问题。休息服务器仍然以411错误答案。
这是我们从cxf.xml文件
的导管配置 <http-conf:conduit name="{http://myhost.com/ChangePassword}WebClient.http-conduit">
<http-conf:client AllowChunking="false"/>
</http-conf:conduit>
日志中的行确认我们的请求的执行绑定到我们的导管配置:
DEBUG o.a.cxf.transport.http.HTTPConduit - Conduit '{http://myhost.com/ChangePassword}WebClient.http-conduit' has been configured for plain http.
明确添加内容长度也无济于事。
Invocation.Builder builder = ...
builder = builder.header(HttpHeaders.CONTENT_LENGTH, 0);
CXF客户端的日志条目确认标题设置,但是当我们嗅探数据包时,我们出人意料地发现,CXF客户端完全忽略了标头设置。未发送内容长度的标题。
这是日志。存在内容长度的标题:
INFO o.a.c.i.LoggingOutInterceptor - Outbound Message
---------------------------
ID: 1
Address: http://myhost.com/ChangePassword?username=abc%40gmail.com&oldPassword=qwerty123&newPassword=321ytrewq
Http-Method: PUT
Content-Type: application/x-www-form-urlencoded
Headers: {Accept=[application/json], client_id=[abcdefg1234567890abcdefg12345678], Content-Length=[0], Content-Type=[application/x-www-form-urlencoded], Cache-Control=[no-cache], Connection=[Keep-Alive]}
--------------------------------------
DEBUG o.apache.cxf.transport.http.Headers - Accept: application/json
DEBUG o.apache.cxf.transport.http.Headers - client_id: abcdefg1234567890abcdefg12345678
DEBUG o.apache.cxf.transport.http.Headers - Content-Length: 0
DEBUG o.apache.cxf.transport.http.Headers - Content-Type: application/x-www-form-urlencoded
DEBUG o.apache.cxf.transport.http.Headers - Cache-Control: no-cache
DEBUG o.apache.cxf.transport.http.Headers - Connection: Keep-Alive
这是数据包嗅探器的输出。内容长度不存在:
PUT http://myhost.com/ChangePassword?username=abc%40gmail.com&oldPassword=qwerty123&newPassword=321ytrewq HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: application/json
client_id: abcdefg1234567890abcdefg12345678
Cache-Control: no-cache
User-Agent: Apache-CXF/3.1.8
Pragma: no-cache
Host: myhost.com
Proxy-Connection: keep-alive
有人知道如何实际禁用块吗?
这是我们的代码:
public static void main(String[] args)
{
String clientId = "abcdefg1234567890abcdefg12345678";
String uri = "http://myhost.com";
String user = "abc@gmail.com";
Client client = ClientBuilder.newBuilder().newClient();
WebTarget target = client.target(uri);
target = target.path("ChangePassword").queryParam("username", user).queryParam("oldPassword", "qwerty123").queryParam("newPassword", "321ytrewq");
Invocation.Builder builder = target.request("application/json").header("client_id", clientId).header(HttpHeaders.CONTENT_LENGTH, 0);
Response response = builder.put(Entity.form(new Form()));
String body = response.readEntity(String.class);
System.out.println(body);
}
版本:
- OS:Windows 7 Enterprise SP1
- Arch:X86_64
- java:1.7.0_80
- cxf:3.1.8
我遇到了一个非常相似的问题,我无法像尝试关闭块那样解决。
我最终做的是将内容长度设置为1并添加一些空白"作为身体。对我来说,似乎在服务器应用程序被拒绝之前的代理服务器,并且通过这样做使我超越了代理服务器,并且服务器能够处理请求,因为它仅根据URL运行。
<</p>