[英]Howto send PUT request without content and Content-Length header with Apache http client?
我想测试(通过自动化测试)服务器(以及所有中间代理)如何响应没有正文和Content-Length
header 的 PUT 请求。
类似于 curl 所做的
curl -XPUT http://example.com
与 Apache HTTP 客户端(4.5.13)
但如果我没有指定正文,它看起来总是添加Content-Length
header 。 Apache HTTP 客户端有什么办法吗?
已经尝试过(没有运气)
final HttpPut request = new HttpPut(url);
request.removeHeaders("Content-Length");
使用请求拦截器修改标准协议处理器生成的请求
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.