我已经成功使用生成了密钥库
keytool -genkeypair -alias SomeAlias -keyalg RSA -validity 365 -keystore NAME.keystore -storetype JKS
将其放在 tomcat 配置目录中,并更新 server.xml 文件以启用 8443 端口监听。
所以我可以访问https://localhost:8443/MyApp
但是当我尝试发布一些数据时https://localhost:8443/MyApp到https://localhost:8443/MyApp
sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效认证路径
我的 POST 函数:
public void HttpsPostData(String data, URL url){
try {
String encodedData = URLEncoder.encode("data", "UTF-8") + "=" + URLEncoder.encode(data, "UTF-8");
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(encodedData);
wr.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
}
in.close();
} catch (IOException ex) {
Logger.getLogger(Sender.class.getName()).log(Level.SEVERE, null, ex);
}
}
我错过了什么?