zoukankan      html  css  js  c++  java
  • httpclient5:信任所有证书,调用公众号接口

    // Trust standard CA and those trusted by our custom strategy
        SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
          // 信任所有
          public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            return true;
          }
        }).build();
        // Allow TLSv1.2 protocol only
        final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
            .setSslContext(sslContext).setTlsVersions(TLS.V_1_2).build();
        final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
            .setSSLSocketFactory(sslSocketFactory).build();
        try (CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build()) {
        // 获得access_token
          final HttpGet httpget = new HttpGet(
              "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=自己的&secret=自己的");
          System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
          final HttpClientContext clientContext = HttpClientContext.create();
          try (CloseableHttpResponse response = httpclient.execute(httpget, clientContext)) {
            System.out.println("----------------------------------------");
            System.out.println(response.getCode() + " " + response.getReasonPhrase());
            System.out.println(EntityUtils.toString(response.getEntity()));
    
            final SSLSession sslSession = clientContext.getSSLSession();
            if (sslSession != null) {
              System.out.println("SSL protocol " + sslSession.getProtocol());
              System.out.println("SSL cipher suite " + sslSession.getCipherSuite());
            }
          }
        }
  • 相关阅读:
    返回到上一页的html代码的几种写法
    记一次网站服务器内存占用过多问题
    rpm命令数据库修复日志
    Linux vmstat命令实战详解
    innodb的innodb_buffer_pool_size和MyISAM的key_buffer_size
    mysql
    如何查看linux系统下的各种日志文件 linux 系统日志的分析大全
    /var/lock/subsys作用
    CentOS目录结构详解
    MySQL体系结构
  • 原文地址:https://www.cnblogs.com/huiy/p/14761639.html
Copyright © 2011-2022 走看看