zoukankan      html  css  js  c++  java
  • apache httpclient 4.5 兼容 http https

     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;
  • 相关阅读:
    pyDNS学习
    BUUCTF password
    攻防世界 easy-apk
    Android Normal writeup
    Jarvis OJ
    阿里云服务器连接(安装)宝塔面板
    bmp格式转为jpeg格式文件
    课设记录-Day15
    课设记录-Day14
    课设记录-Day13
  • 原文地址:https://www.cnblogs.com/Zombie-Xian/p/5355295.html
Copyright © 2011-2022 走看看