最近,在使用HttpClient访问Java应用程序中的第三方服务(CURL )时,我遇到了如下问题:
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
....我在JDK 7中得到了这个问题。通过对这个问题的研究,我发现了两个建议:
因此,我试图像一样理解,与Java7或更低版本相比,SSL握手是如何在Java8中发生的?我可以在JDK7中解决这个问题
码蛇形
public String getProduct(final String accessToken) throws IOException, ParseException {
log.info("accessToken: " + accessToken);
final String stringUrl = "https://api.molt.in/v1/products";
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet getRequest = new HttpGet(stringUrl);
getRequest.setHeader("Authorization", "Bearer " + accessToken);
HttpContext httpContext = new BasicHttpContext();
HttpResponse response = httpClient.execute(getRequest, httpContext);
log.info("Response Code : " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
log.info("result: " + result);
rd.close();
return result.toString();
}~问候,
钱丹
发布于 2017-04-29 07:34:18
服务器关闭握手,因为客户端使用不支持的协议。请参见这个问题,其中建议使用以下方式启动Java 7:
-Dhttps.protocols=TLSv1.1,TLSv1.2如果服务器证书不受信任,您将从客户端获得一个错误(javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX路径构建失败),并且它是这样工作的:在您的示例"api.molt.in“中,Java检查服务器的证书以确保它正在交谈的机器实际上是它声称的那个机器。支票的工作方式如下:
https://stackoverflow.com/questions/43692884
复制相似问题