1
我正在使用ApacheConnection提供程序的球衣客戶端。如何使用Jersey和Apache Http客戶端進行代理驗證?
Builder builder = RequestConfig.custom().setConnectTimeout(timeout);
List<Proxy> proxies = ProxyManager.getInstance().select(baseUrl.toURI());
if (useProxy) {
...
builder.setProxy(new HttpHost(proxyUri.getHost(), proxyUri.getPort()));
}
RequestConfig requestConfig = builder.build();
final ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
clientConfig.connectorProvider(new ApacheConnectorProvider());
client = ClientBuilder.newBuilder().withConfig(clientConfig).sslContext(getSSLContext()).build();
client.property(ClientProperties.CONNECT_TIMEOUT, 5000);
但是如何爲代理驗證添加用戶名和密碼?
看起來像apache連接提供程序不使用標準的java代理選擇器機制。
你可以使用'DefaultProxyRoutePlanner':'DefaultProxyRoutePlanner routePlanner =新DefaultProxyRoutePlanner(新HttpHost(,));'。然後你設置客戶端的路由規劃器:'HttpClient client = HttpClients.custom()。setRoutePlanner(routePlanner).build();'。 –
aribeiro
但是在哪裏設置用戶名和密碼? – gorootde
爲此,請看下面的答案:http://stackoverflow.com/a/36907908/1346996。 – aribeiro