【发布时间】:2018-10-10 18:42:20
【问题描述】:
我想读取用户输入的 https URL 的内容,我们没有任何关于证书密钥和 jks 等的数据:
<!DOCTYPE html>
<html>
<head>
<title>Total Synthesis of Fidaxomicin | | download</title>
</head>
<body>
<form action="testSSL.jsp">
<input name="sslRandomUrl" type="text">
<input type="submit" value="opensslUrl" >
</form>
</body>
这是jsp:
<%@page import="java.net.URL"%>
<%@page import="javax.net.ssl.HttpsURLConnection"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
String url = request.getParameter("sslRandomUrl");
System.out.println("How to open like web browser? >>>"+url);
URL pdfContainerUrl = new URL(url);
HttpsURLConnection conn2 = (HttpsURLConnection) pdfContainerUrl.openConnection();// دقت شود https
StringBuilder result = new StringBuilder();
conn2.setRequestMethod("GET");
BufferedReader br2 = new BufferedReader(new InputStreamReader(conn2.getInputStream(), "UTF-8"));
String line2;
while ((line2 = br2.readLine()) != null) {
result.append(line2);
System.out.println(line2);
}
out.print(result);
%>
但我对很多网址都有这个错误:
ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径
如何强制jdk打开所有https URL?
【问题讨论】:
-
如果您覆盖它,您知道安全隐患吗?
-
亲爱的朋友,有任何关于安全隐患的问题,请只是工作代码。