DBILITY

java.security.cert.CertificationException : No subject alternative DNS name matching "xxx" found 본문

java

java.security.cert.CertificationException : No subject alternative DNS name matching "xxx" found

DBILITY 2022. 8. 11. 11:27
반응형

hostname verifier에러에 그냥 구글 검색으로 대응했다.

기록해 두자.

try {
    URL url = new URL(requestURL);
    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) {
        }
    } };
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    httpConn = (HttpsURLConnection) url.openConnection();
} catch( Exception e) {
    System.out.println(e.toString());
}
반응형

'java' 카테고리의 다른 글

java substring usage  (0) 2022.08.25
java 7 multiple exception catch  (0) 2016.10.04
Comments