Parameter settings, code writing, and risks that you must know when using httpclient

Reference: http://jinnianshilongnian.iteye.com/blog/2089792


/**
     *  
     * Method name: createSSLClientDefault
     * Author: Zhouyh
     * Creation time: 2015-10-14 03:03:30 PM
     * Description: Create httpclient using SSL for https
     * @return
     */  
    public static CloseableHttpClient createSSLClientDefault(){       
        try {             
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy(){  
            // trust all  
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {  
                return true;  
            }}).build();  
  
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);  
  
            return HttpClients.custom().setSSLSocketFactory(sslsf).build();  
  
        } catch (KeyManagementException e) {  
            e.printStackTrace ();  
        } catch (NoSuchAlgorithmException e) {  
            e.printStackTrace ();  
        } catch (KeyStoreException e) {  
            e.printStackTrace ();  
        }  
              
        return  HttpClients.createDefault();  
    }  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326690344&siteId=291194637