http请求https出现SSL证书问题的解决方法

最近在使用http请求shopify的时候出现SSL证书问题,由于shopify的API是https,所以我们需要在请求的时候添加忽略SSL。

具体实现代码:

    /**
     * 添加忽略ssl证书
     * @return
     */
    public static CloseableHttpClient createSSLInsecureClient() {
        try {
            SSLContext sslContext = (new SSLContextBuilder()).loadTrustMaterial(new TrustStrategy() {
                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    return true;
                }
            }).build();
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
            return HttpClients.custom().setSSLSocketFactory(sslsf).build();
        } catch (GeneralSecurityException var2) {
            throw new RuntimeException(var2);
        }
    }

判断如果是https请求则使用此方法创建HttpClient

你可能感兴趣的:(JavaScript)