http请求忽略ssl证书
- 2019-07-18 10:05:00
- admin 原创
- 2447
在调用第三方接口的时候出现
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid
http请求忽略ssl证书
在调用第三方的接口的时候,通过浏览器直接访问接口地址是能访问,通过postman测试是不行的,通过接口调用也是不行的,最后发现域名是https的,请求的时候要忽略ssl证书
引入的jar包如下
import javax.net.ssl.SSLContext; import java.security.cert.CertificateException; import java.security.cert.X509Certificate;
public static CloseableHttpClient getIgnoeSSLClient() { SSLContext sslContext=null; try{ sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { return true; } }).build(); }catch (Exception e){ e.printStackTrace(); } //创建httpClient CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext). setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); return client; }
发表评论
文章分类
联系方式
联系人: | 郑州-小万 |
---|---|
电话: | 13803993919 |
Email: | 1027060531@qq.com |
QQ: | 1027060531 |
网址: | www.wanhejia.com |
Update Required
To play the media you will need to either update your browser to a recent version or update your Flash plugin.