用 httpClient 连接 https 服务,如果证书与 host 不匹配,就会报:Certificate for <124.xxx.xxx.xxx> doesn't match any of the subject alternative names

可以通过在创建 SSLConnectionSocketFactory 时增加一个参数,禁用这个匹配性校验。

            SSLContext sslContext = new SSLContextBuilder()
                    .loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true)
                    .build();
            HostnameVerifier verifier = (s, sslSession) -> true;
            SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslContext, verifier);
            return HttpClients.custom()
                    .setSSLSocketFactory(factory)
                    .build();

 

相关文章:

  • 2021-11-20
  • 2021-04-30
  • 2022-12-23
  • 2022-02-14
  • 2021-11-15
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-09
  • 2021-06-03
  • 2021-09-18
  • 2022-12-23
  • 2022-02-03
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案