常用代码块:创建httpclient

HttpGet httpGet = new HttpGet(url);
SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(TrustSelfSignedStrategy.INSTANCE).build();


RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(3000)
.setConnectionRequestTimeout(3000).setSocketTimeout(3000).build();


CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslcontext)
.setSSLHostnameVerifier(new MyHostnameVerifier())
.setDefaultRequestConfig(requestConfig).build();


CloseableHttpResponse response = httpclient.execute(httpGet);

posted @ 2016-07-25 08:05  范世强  阅读(436)  评论(0编辑  收藏  举报