https 모든 인증 서 를 신뢰 합 니 다.

4053 단어 자바
public static class WebClientDevWrapper {  
        public static org.apache.http.client.HttpClient wrapClient(
            org.apache.http.client.HttpClient base) {  
            try {  
                SSLContext ctx = SSLContext.getInstance("TLS");  
                X509TrustManager tm = new X509TrustManager() {  
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {  
                        return null;  
                    }  
                    public void checkClientTrusted(X509Certificate[] arg0, String arg1) 
                    throws CertificateException {}  
                    throws CertificateException {}  
                    @Override  
                    public void checkClientTrusted(  
                            java.security.cert.X509Certificate[] chain,  
                            String authType)  
                            throws java.security.cert.CertificateException {  
                        // TODO Auto-generated method stub  

                    }  
                    @Override  
                    public void checkServerTrusted(  
                            java.security.cert.X509Certificate[] chain,  
                            String authType)  
                            throws java.security.cert.CertificateException {  
                        // TODO Auto-generated method stub  

                    }  
                };  
                ctx.init(null, new TrustManager[] { tm }, null);  
                org.apache.http.conn.ssl.SSLSocketFactory ssf = 
                        new org.apache.http.conn.ssl.SSLSocketFactory(ctx, org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);  
                SchemeRegistry registry = new SchemeRegistry();  
                registry.register(new Scheme("https", 443, ssf));  
                ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(registry);  
                return new DefaultHttpClient(mgr, base.getParams());  
            } catch (Exception ex) {  
                ex.printStackTrace();  
                return null;  
            }  
        }  

    }

쓰다
HttpClient httpClient = new DefaultHttpClient();
httpClient = WebClientDevWrapper.wrapClient(httpClient);//        
HttpPost httpPost = new HttpPost(bean.getReconUrl());

좋은 웹페이지 즐겨찾기