[英]How to use SSL Client certificate with Apache commons http client
[英]How to handle invalid SSL certificate with Apache client 4.5.5?
我正在尝试使用Apache Client 4.5.5连接到我的Web服务器之一。
我正在尝试使用SSLContextBuilder,但现在似乎已弃用它,我不想使用已弃用的东西。
有人可以建议最新的处理无效认证的方法吗?
下面是我的代码,它工作正常,但是不建议使用SSLContext,SSLContextBuilder,loadTrustmaterial。
SSLContextBuilder sscb = new SSLContextBuilder();
sscb.loadTrustMaterial(null, new org.apache.http.conn.ssl.TrustSelfSignedStrategy());
SSLContext sslContext = sscb.build();
SSLConnectionSocketFactory sslSocketFactory =
new SSLConnectionSocketFactory(sslContext, new org.apache.http.conn.ssl.DefaultHostnameVerifier());
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.setSSLSocketFactory(sslSocketFactory)
.setConnectionManager(connectionMgr)
.build();
try {
HttpPost httppost = new HttpPost("myURL");
Apache HttpClient 4.5.5
HttpClient httpClient = HttpClients
.custom()
.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, TrustAllStrategy.INSTANCE).build())
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.