我如何创建一个不验证 SSL 证书的 CloseableHttpPipeliningClient?
How do I provide create a CloseableHttpPipeliningClient that doesn't validate SSL certificates?
我正在尝试使用支持 HTTP 管道的 Apache HttpAsyncClient。我想添加一个类似于此处 (以及许多其他地方)所讨论内容的全信任 SSL 策略。但是我看不到任何使用自定义 SSLContext 获得流水线客户端构建器的方法:HttpAsyncClients.createPipelining()
方法不 return 构建器,并且 HttpAsyncClients.custom()
构建器不构建 ClosableHttpPipeliningClient
这应该可以满足您的需求
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();
我正在尝试使用支持 HTTP 管道的 Apache HttpAsyncClient。我想添加一个类似于此处 (以及许多其他地方)所讨论内容的全信任 SSL 策略。但是我看不到任何使用自定义 SSLContext 获得流水线客户端构建器的方法:HttpAsyncClients.createPipelining()
方法不 return 构建器,并且 HttpAsyncClients.custom()
构建器不构建 ClosableHttpPipeliningClient
这应该可以满足您的需求
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();