同一个方法,用 JUnit 测试类跑没有问题,程序运行起来定时器跑就抛异常(
No subject alternative names present
),半天了没有头绪,求帮忙分析分析. JDK17,springboot2.7.1,JUnit5
1
blankmiss 2022-12-13 15:41:35 +08:00
你为什么不发哥 gist 出来
|
2
Hancock 2022-12-13 15:48:53 +08:00
用 OkHttp 的 sslSocketFactory 、hostnameVerifier 看看呢
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/ssl-socket-factory/ |
3
mengyxu OP @Hancock 我用 apache 的 httpclient 是没有问题的,我是想着换成 jdk11 自带 httpClient,结果遇到了这个问题
|
4
b2byco 2022-12-13 22:48:32 +08:00
试试这个
try { X509TrustManager x509TrustManager = new X509TrustManager() {@ Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}@ Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}@ Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }; SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init((KeyManager[]) null, new X509TrustManager[] { x509TrustManager }, (SecureRandom) null); HttpClient client = HttpClient.newBuilder().sslContext(sslContext).followRedirects(HttpClient.Redirect.ALWAYS).version(HttpClient.Version.HTTP_1_1).build(); URI uri = new URI("https", "//", null); HttpRequest r = HttpRequest.newBuilder().uri(uri).GET().build(); var s = client.send(r, HttpResponse.BodyHandlers.ofString()); System.out.println(s.body()); } catch(Exception e) {} |