Apache HttpClient不发送代理身份验证凭据

时间:2015-08-03 16:06:58

标签: java httpclient apache-httpclient-4.x solrj

我使用SolrJ 4.7.2和HttpClient 4.3.1并遇到代理身份验证的一些困难。

我使用以下代码通过一个服务器代理到一个单独的Solr实例。代理代码正在按预期工作,但是当我启用基本身份验证时,它似乎没有通过任何凭据发送到代理。我已经尝试了我能想到的所有可能的属性组合,但已经碰到了一堵砖墙。任何帮助将不胜感激!

RequestConfig requestConfig = RequestConfig.custom()
    .setConnectTimeout(this.connectionTimeout)
    .setConnectionRequestTimeout(this.connectionTimeout)
    .setSocketTimeout(this.connectionTimeout)
    .build();

HttpClientBuilder httpClientBuilder = HttpClients.custom()
    .setDefaultRequestConfig(requestConfig)
    .setMaxConnTotal(128)
    .setMaxConnPerRoute(32)
    .disableRedirectHandling();

HttpHost proxy = new HttpHost(proxyUrl, proxyPort, proxyProtocol);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
    new AuthScope(proxyUrl, proxyPort, AuthScope.ANY_REALM, "basic"),
    new UsernamePasswordCredentials(proxyUsername, proxyPassword));

httpClientBuilder
    .setDefaultCredentialsProvider(credentialsProvider)
    .setTargetAuthenticationStrategy(new ProxyAuthenticationStrategy())
    .setRoutePlanner(routePlanner);

CloseableHttpClient httpClient = httpClientBuilder.build();


HttpSolrServer solrServer = new HttpSolrServer(baseUrl, httpClient);

0 个答案:

没有答案