如何禁用来自 apache httpclient 4 的默认请求标头?
我正在使用apache common httpclient 4.3.3来发出http 1.0请求。以下是我如何提出请求
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
post.setProtocolVersion(new ProtocolVersion("HTTP", 1, 0));
// trying to remove default headers but it doesn't work
post.removeHeaders("User-Agent");
post.removeHeaders("Accept-Encoding");
post.removeHeaders("Connection");
post.setEntity(new ByteArrayEntity(ba) );
HttpResponse response = client.execute(post);
但是,我可以看到还有其他标头自动添加到我对服务器的请求中,例如
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.3.3 (java 1.5)
Accept-Encoding: gzip,deflate
我如何告诉 httpclient 不包含任何其他标头?我试图用post.removeHeaders(xxxx)删除这些标题,但它不起作用。你能告诉我怎么做吗?
谢谢