在 Jersey1.x 上为客户端设置代理很容易:
config.getProperties().put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyUrl);
但是如何为Jersey2.x客户端添加http代理呢? 我检查了源代码,没有找到实现:
org.glassfish.jersey.client.HttpUrlConnector
谢谢!
最佳答案
谢谢@feuyeux,该解决方案对我有用, ps,下面的代码适用于具有http基本身份验证的代理:
ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.property(ClientProperties.PROXY_URI, proxy);
config.property(ClientProperties.PROXY_USERNAME,user);
config.property(ClientProperties.PROXY_PASSWORD,pass);
Client client = JerseyClientBuilder.newClient(config);
希望能帮助到别人
关于jersey-client - 如何为 Jersey2 客户端添加 http 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18942648/