我正在尝试将 Apache HttpAsyncClient 与 HTTP 流水线支持一起使用。我想添加一个信任所有 SSL 策略,类似于这里讨论的忽略 Apache HttpClient 4.3 中的 SSL 证书(以及其他一些地方)。但我看不到任何使用自定义 SSLContext 获取流水线客户端构建器的方法:该HttpAsyncClients.createPipelining()
方法不返回构建器,并且HttpAsyncClients.custom()
构建器不构建ClosableHttpPipeliningClient
1 回答
1
这可能应该做你想要的
DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT);
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(
ioReactor,
RegistryBuilder.<SchemeIOSessionStrategy>create()
.register("http", NoopIOSessionStrategy.INSTANCE)
.register("https", new SSLIOSessionStrategy(sslContext))
.build());
CloseableHttpPipeliningClient httpClient = HttpAsyncClients.createPipelining(cm);
httpClient.start();
于 2017-11-02T14:52:20.743 回答