作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 java 访问我的 api,但出现以下错误:
javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_required
在我的个人 Windows 计算机上测试代码时,我没有收到此错误。但是这个错误确实发生在我的运行带有 openjdk 11 的 Ubuntu 的 linux 生产服务器上。
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/
我正在尝试从 java 访问我的 api,但出现以下错误: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate
我是一名优秀的程序员,十分优秀!