带有重定向的Java Apache HTTP异步客户端问题https url

时间:2015-07-23 07:27:53

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

我试图在重定向中调用包含url和https协议的url时遇到一般SSLEngine问题。

我正在使用HttpAsyncClient版本4.1

例如为: 主网址https://example.com重定向到https://example.net

在HTTP的情况下正常工作。

我尝试使用:

TrustStrategy acceptingTrustStrategy = new TrustStrategy() {

      @Override
      public boolean isTrusted(X509Certificate[] certificate, String authType) {
        return true;
      }
    };
    SSLContext sslContext = null;
    try {
      sslContext = SSLContexts.custom().useTLS().loadTrustMaterial(null, acceptingTrustStrategy).build();
    } catch (Exception e) {
      // Handle error
    }
CloseableHttpAsyncClient httpClient =
        HttpAsyncClientBuilder.create().setConnectionManager(connManager)
            .setDefaultRequestConfig(HttpClientUtils.configForClient)
            .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
            .setSSLContext(sslContext).setRedirectStrategy(LaxRedirectStrategy.INSTANCE).build();

0 个答案:

没有答案