[英]Add http header “User-Agent” to HTTP CONNECT request
Prerequisites 先决条件
Problem 问题
I try to call a https encrypted site via http4 component. 我尝试通过http4组件调用https加密的站点。 The proxy which is in between my server and the internet (target server) checks the header "User-Agent" and rejects the request if it is empty.
在我的服务器和Internet(目标服务器)之间的代理检查标头“ User-Agent”,如果请求为空,则拒绝该请求。
The connect-Request does not contain the http header "User-Agent". connect-Request不包含http头“ User-Agent”。
In org.apache.http.impl.execchain.MainClientExec in method private boolean createTunnelToTarget(AuthState proxyAuthState, HttpClientConnection managedConn, HttpRoute route, HttpRequest request, HttpClientContext context) throws HttpException, IOException
following is called: 在org.apache.http.impl.execchain.MainClientExec中,方法
private boolean createTunnelToTarget(AuthState proxyAuthState, HttpClientConnection managedConn, HttpRoute route, HttpRequest request, HttpClientContext context) throws HttpException, IOException
以下是private boolean createTunnelToTarget(AuthState proxyAuthState, HttpClientConnection managedConn, HttpRoute route, HttpRequest request, HttpClientContext context) throws HttpException, IOException
的调用:
BasicHttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.getProtocolVersion());
this.requestExecutor.preProcess(connect, this.proxyHttpProcessor, context);
this.requestExecutor.preProcess
adds header "Host" and "Proxy-Connection" to the HTTP CONNECT request but not "User-Agent". this.requestExecutor.preProcess
将标头“ Host”和“ Proxy-Connection”添加到HTTP CONNECT请求中,但未添加“ User-Agent”。
How can I add the Header "User-Agent" to the HTTP CONNECT request? 如何将标头“ User-Agent”添加到HTTP CONNECT请求?
Regards, 问候,
Max 马克斯
The problem is solved in httpclient 4.4.1. 该问题已在httpclient 4.4.1中解决。
In class org.apache.http.impl.client.HttpClientBuilder the httpprocessor is initialzed with a HttpRequestInterceptor for User-Agent: 在类org.apache.http.impl.client.HttpClientBuilder中,使用针对用户代理的HttpRequestInterceptor初始化httpprocessor:
ClientExecChain execChain = createMainExec(
requestExecCopy,
connManagerCopy,
reuseStrategyCopy,
keepAliveStrategyCopy,
new ImmutableHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),
targetAuthStrategyCopy,
proxyAuthStrategyCopy,
userTokenHandlerCopy);
The solution is to update the httpclient version from 4.3.3 to 4.4.1 . 解决方案是将httpclient版本从4.3.3更新到4.4.1。 In maven I had to define the dependency so that not the verson used by camel was choosen.
在Maven中,我必须定义依赖项,以便不选择骆驼使用的版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.