[英]Howto send PUT request without content and Content-Length header with Apache http client?
I'd like to test (via automated test) how server (and all proxies in-the-middle) responds to a PUT request without body and Content-Length
header.我想测试(通过自动化测试)服务器(以及所有中间代理)如何响应没有正文和
Content-Length
header 的 PUT 请求。
Similar to what curl does类似于 curl 所做的
curl -XPUT http://example.com
with Apache HTTP client (4.5.13)与 Apache HTTP 客户端(4.5.13)
But it looks like it always adds Content-Length
header if I specify no body.但如果我没有指定正文,它看起来总是添加
Content-Length
header 。 Is there any way to do that with Apache HTTP client? Apache HTTP 客户端有什么办法吗?
Already tried (no luck)已经尝试过(没有运气)
final HttpPut request = new HttpPut(url);
request.removeHeaders("Content-Length");
Use a request interceptor to modify requests generated by the standard protocol processor使用请求拦截器修改标准协议处理器生成的请求
CloseableHttpClient httpClient = HttpClients.custom()
.addInterceptorLast((HttpRequestInterceptor) (request, context) ->
request.removeHeaders(HttpHeaders.CONTENT_LENGTH))
.build();
HttpPut httpPut = new HttpPut("http://httpbin.org/put");
httpClient.execute(httpPut, response -> {
EntityUtils.consume(response.getEntity());
return null;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.