【发布时间】:2021-05-15 18:29:08
【问题描述】:
我正在尝试从 java 访问我的 api,但出现以下错误:
javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_required
在我的个人 Windows 计算机上测试代码时,我没有收到此错误。但是这个错误确实发生在我运行 Ubuntu 和 openjdk 11 的 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 服务器上是否配置不正确?
更新:我的问题还没有解决,我还在寻找答案。我在互联网上找不到任何信息丰富的博客或信息。
【问题讨论】:
-
这个问题已经回答here
-
问题是我已经添加了我的源服务器的证书。如果需要,我不确定如何添加缺少的 cloudflare 证书。此外,您链接的帖子是握手错误
标签: java ssl cloudflare httpsurlconnection