我正在尝试使用具有 HTTP 管道支持的 Apache HttpAsyncClient。我想添加一个类似于此处讨论的全信任 SSL 策略 Ignoring SSL certificate in Apache HttpClient 4.3 (以及许多其他地方)。但我没有看到任何使用自定义 SSLContext 获取管道客户端生成器的方法:HttpAsyncClients.createPipelined()
方法不返回生成器,并且 HttpAsyncClients.custom()
构建器未构建 ClosableHttpPipelinedClient
最佳答案
这应该可以达到你想要的效果
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();
关于java - 如何创建一个不验证 SSL 证书的 CloseableHttpPipelinedClient?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47045748/