博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HttpClient忽略ssl验证
阅读量:6238 次
发布时间:2019-06-22

本文共 1035 字,大约阅读时间需要 3 分钟。

hot3.png

package cc.c3p0.common.utils;import org.apache.http.conn.ssl.NoopHostnameVerifier;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.ssl.SSLContexts;import org.apache.http.ssl.TrustStrategy;import javax.net.ssl.SSLContext;import java.security.cert.CertificateException;import java.security.cert.X509Certificate;public class HttpUtils {    public static CloseableHttpClient getIgnoeSSLClient() throws Exception {        SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {            @Override            public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {                return true;            }        }).build();        //创建httpClient        CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).                setSSLHostnameVerifier(new NoopHostnameVerifier()).build();        return client;    }}

 

转载于:https://my.oschina.net/mobinchao/blog/1605183

你可能感兴趣的文章