如何解决HttpsUrlConnection SSLHandshakeException certificate_required
我正在尝试从 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 服务器上配置不正确?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。