开发者社区 问答 正文

[求助!] RestTemplate 请求https接口报错的问题, 查无所获, ?报错

使用restTemplate在请求https接口的时候不通,使用方法:

import org.springframework.web.client.RestTemplate;
......
ResponseEntity<String> response = restTempLate.exchange(urlAppender.toString(), HttpMethod.POST, request, String.class);

报错信息:

Caused by: javax.net.ssl.SSLException: SSL peer shut down incorrectly

服务器:Windows server 2012
证书:请忽略https证书问题

curl https://ip:port 不通

防火墙中已经开放相关的端口和IP

服务器端支持的https协议有:

System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2,SSLv3");

展开
收起
爱吃鱼的程序员 2020-06-23 14:15:55 1665 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    在服务器本地curlhttps://ip:port,看看https服务本身是否有问题?

    privatestaticRestTemplaterestTemplate()throwsKeyManagementException,NoSuchAlgorithmException,KeyStoreException{
    TrustStrategyacceptingTrustStrategy=newTrustSelfSignedStrategy();
    SSLContextsslContext=org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null,acceptingTrustStrategy)
    .build();
    SSLConnectionSocketFactorycsf=newSSLConnectionSocketFactory(sslContext,NoopHostnameVerifier.INSTANCE);
    CloseableHttpClienthttpClient=HttpClients.custom().setSSLSocketFactory(csf).build();
    HttpComponentsClientHttpRequestFactoryrequestFactory=newHttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(httpClient);
    RestTemplaterestTemplate=newRestTemplate(requestFactory);
    returnrestTemplate;
    }

    2020-06-23 14:16:11
    赞同 展开评论