Trusting all certificates using HttpClient over HTTPS

后端 未结 21 2299
北恋
北恋 2020-11-21 04:50

Recently posted a question regarding the HttpClient over Https (found here). I\'ve made some headway, but I\'ve run into new issues. As with my last problem, I

21条回答
  •  旧巷少年郎
    2020-11-21 05:18

    work with all https

    httpClient = new DefaultHttpClient();
    
    SSLContext ctx = SSLContext.getInstance("TLS");
    X509TrustManager tm = new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { }
    
        public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { }
    
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    };
    
    ctx.init(null, new TrustManager[]{tm}, null);
    SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    
    httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, ssf));
    

提交回复
热议问题