1 String responseContent = "";
 2 try {
 3     SSLContextBuilder contextBuilder = new SSLContextBuilder();
 4     contextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
 5     SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(contextBuilder.build());
 6     CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).build();
 7     HttpGet httpGet = new HttpGet(requestUrl);
 8     CloseableHttpResponse response = httpclient.execute(httpGet);
 9     try {
10         HttpEntity entity = response.getEntity();
11         if (null != entity) {
12             responseContent = EntityUtils.toString(entity, ContentType.getOrDefault(entity).getCharset());
13             EntityUtils.consume(entity);
14         }
15     } finally {
16         response.close();
17     }
18 } catch (KeyStoreException e) {
19     e.printStackTrace();
20 } catch (NoSuchAlgorithmException e) {
21     e.printStackTrace();
22 } catch (KeyManagementException e) {
23     e.printStackTrace();
24 }
25 return responseContent;

 

相关文章:

  • 2022-02-17
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-07-19
  • 2021-12-10
  • 2021-08-20
  • 2021-10-27
猜你喜欢
  • 2022-12-23
  • 2022-02-04
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-01-11
相关资源
相似解决方案