如何为Jersey2客户端添加http代理 [英] How to add a http proxy for Jersey2 Client
本文介绍了如何为Jersey2客户端添加http代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Jersey1.x上为客户端设置代理很容易:
It's easy to set a proxy for client on Jersey1.x:
config.getProperties().put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyUrl);
但是如何为Jersey2.x客户端添加http代理? 我检查了源代码,却没有发现实现可以在以下位置进行实现:
But how to add a http proxy for Jersey2.x client? I checked the source code and didn't find the implementation does that in:
org.glassfish.jersey.client.HttpUrlConnector
org.glassfish.jersey.client.HttpUrlConnector
谢谢!
推荐答案
在运行时设置不同的代理不是一个好的解决方案.因此,我使用apache连接器来这样做:
To set different proxy on runtime is not good solution. Accordingly, I used apache connector to do so:
添加了apache连接器依赖项定义:
add apache connector dependency defined:
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
</dependency>
将apache连接器添加到客户端
add apache connector to client
config.property(ApacheClientProperties.PROXY_URI, proxyUrl);
Connector connector = new ApacheConnector(config);
config.connector(connector);
这篇关于如何为Jersey2客户端添加http代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文