• java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx.xxx found


    https与http不同的是,https加密,需要验证证书,而http不需要。

    在连接的代码中加上:

    static {
            disableSslVerification();
        }
    
        private static void disableSslVerification() {
            try
            {
                // Create a trust manager that does not validate certificate chains
                TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }
                    public void checkClientTrusted(X509Certificate[] certs, String authType) {
                    }
                    public void checkServerTrusted(X509Certificate[] certs, String authType) {
                    }
                }
                };
    
                // Install the all-trusting trust manager
                SSLContext sc = SSLContext.getInstance("SSL");
                sc.init(null, trustAllCerts, new java.security.SecureRandom());
                HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    
                // Create all-trusting host name verifier
                HostnameVerifier allHostsValid = new HostnameVerifier() {
                    public boolean verify(String hostname, SSLSession session) {
                        return true;
                    }
                };
    
                // Install the all-trusting host verifier
                HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (KeyManagementException e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    双循环建表____1911年 为 辛亥年
    技巧方法
    sscanf
    02-02环境准备-pyenv与virtualenv以及venv方案对比
    02-01环境准备-virtualenv和venv
    02-01环境准备-pyenv
    【转】解决weblogic启动慢和创建域慢的方法
    chrome新版打开新标签页自动打开谷歌主页
    centos6分辨率设置
    12-openldap使用AD密码
  • 原文地址:https://www.cnblogs.com/Springmoon-venn/p/7504901.html
Copyright © 2020-2023  润新知