问题描述
我正在尝试从 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 (将#修改为@)