nested exception is javax.net.ssl.SSLException: Received fatal alert: protocol_version
报错:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://xxxxx": Received fatal alert: protocol_version; nested exception is javax.net.ssl.SSLException: Received fatal alert: protocol_version
使用 restTemplate.postForObject 请求接口报错,之前访问的是http,没有报错,
原本代理里使用的TLS版本为1.0,访问 https://myssl.com/ ,输入待检测的访问域名,
查询结果:协议与套件->支持协议-> 获取支持的TLS协议版本
修改Template的配置,修改版本配置,如下
public static RestTemplate getRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext,
new String[]{"TLSv1.2"},
null,
NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return new RestTemplate(requestFactory);
}

浙公网安备 33010602011771号