gpt4 book ai didi

java - HttpsUrlConnection SSLHandshakeException certificate_required

转载 作者:行者123 更新时间:2023-12-04 22:42:11 28 4
gpt4 key购买 nike

我正在尝试从 java 访问我的 api,但出现以下错误:

javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_required
在我的个人 Windows 计算机上测试代码时,我没有收到此错误。但是这个错误确实发生在我的运行带有 openjdk 11 的 Ubuntu 的 linux 生产服务器上。
该服务器托管在同一台 ubuntu 服务器上,并使用 Cloudflare SSL Full 代理
HttpsURLConnection con = null;
try {
URL url = new URL("https://www.example.com/");
con = (HttpsURLConnection) url.openConnection();
con.addRequestProperty("XF-Api-Key", "key");
con.addRequestProperty("XF-Api-User", "1");
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
con.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/json");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null)
content.append(inputLine);
in.close();

System.out.println(content.toString());
} catch (Exception e) {
e.printStackTrace();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
System.out.println(content.toString());
}
} catch (Exception exp) {
System.out.println("Cant load data from API");
exp.printStackTrace();
} finally {
if (con != null)
con.disconnect();
}
我的 linux 服务器上是否配置不正确?
更新:我的问题还没有解决,我还在寻找答案。我在互联网上找不到任何信息丰富的博客或信息。

最佳答案

服务器期望客户端提供一个它信任的证书,所以客户端需要配置一个 Keystore - 见 https://www.baeldung.com/java-https-client-certificate-authentication

关于java - HttpsUrlConnection SSLHandshakeException certificate_required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67550047/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com