![](/img/trans.png)
[英]Java -> Flask Https Request: javax.net.ssl.SSLHandshakeException: PKIX path building failed
[英]Curl Request to https endoint working but java client request fails with Error 'javax.net.ssl.SSLHandshakeException'
我试图通过使用Java客户端发出GET请求来连接到https端点。 端点就像这个' https:// domain / path / {token}',但每次我做一个reqeust我得到'javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure'例外,我搜索了很多网站,但没有运气。 有趣的是,当我通过POSTMAN从不同的主机(窗口)发出相同的请求时它也可以工作,我也复制了从POSTMAN生成的curl命令并在我的客户端运行的HOST上运行它也可以正常工作。 只有java代码无法连接到端点。 现在我的问题是:
--->这是证书问题吗?
--->如果是这样,curl如何在不需要证书的情况下工作。
谢谢。
注意:以下是已经尝试过的事情:
- >使用curl命令为java客户端连接设置相同的HEADERS集。
- >也使用了备用休息客户端(okhttp3)和HttpClient库,但得到了相同的异常。
请在下面找到工作curl命令:
curl -X GET \
https://domain/x/y/XUwDummyTokenRKZ80EnxDCJlM \
-H 'Accept: */*' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Host:hostname' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache
还有用于连接到https端点的java客户端代码:
public void printGetResult( String destUrlStr ) {
try {
URL url = new URL(destUrlStr);
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setRequestMethod( "GET" );
InputStream is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String inputLine;
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
}
br.close();
}catch(Exception e) {
System.out.println("exception is"+e);
}
}
预期结果:json
(我知道在我的curl请求中我已将accept设置为*,但它有效)
实际结果:
javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure
您必须将远程服务器证书添加到java的Truststore 。 有几种方法可以做到这一点。 这是一个例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.