https请求peer not authorize,包装HttpClient

/*
This code is public domain: you are free to use, link and/or modify it in any way you want, for all purposes including commercial applications.
*/
public class WebClientDevWrapper {
        public static HttpClient wrapClient(HttpClient base) {
                try {
                        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);
                        ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                        ClientConnectionManager ccm = base.getConnectionManager();
                        SchemeRegistry sr = ccm.getSchemeRegistry();
                        sr.register(new Scheme("https", ssf, 443));
                        return new DefaultHttpClient(ccm, base.getParams());
                } catch (Exception ex) {
                        ex.printStackTrace();
                        return null;
                }
        }
}


你可能感兴趣的:(https请求peer not authorize,包装HttpClient)