创建忽略证书验证的CloseableHttpClient

释放双眼,带上耳机,听听看~!

项目中需要创建忽略证书的http请求,在网上搜索了一下,好多都是大段大段的代码,并且不清不楚的。
本人阅读java源码,现提供最简洁的创建忽略证书验证的https请求。

/**
 * 获取忽略证书验证的client
 *
 * @return
* @throws Exception
 */

public CloseableHttpClient getIgnoeSSLClient() throws Exception {
   SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
      @Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
         return true;
      }
   }).build();

   //创建httpClient
CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).
         setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
   return client;
}

【转自慕课】https://www.imooc.com

PHP

命令行执行php出现PHP Fatal error Class Redis not found in 错误

2022-3-3 17:28:54

PHP

Linux 教程持续更新中

2022-3-3 17:33:29

搜索