java - PKIX 路径构建失败:
问题描述
我收到 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certificate path to requested target exception,如何解决?这是我的密钥库
KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
String pin = " ";
ks.load(null, pin.toCharArray());
Protocol myProtocol = new Protocol("https", new MySSLSockectFactory(), 443);
httpclient.getHostConfiguration()
.setHost("test.euniwizarde.com", 443, myProtocol);
HostConfiguration hostConfiguration = httpclient.getHostConfiguration();
String hostURL = hostConfiguration.getHostURL();
System.out.println("hostURL============" + hostURL);
BufferedReader br = null;
setVisible(false);
PostMethod postMethod = new PostMethod(hostURL);
System.out.println("postmethod " + postMethod);
postMethod.addParameter("userid", "" + userId);
postMethod.addParameter("serialNumber", "" + serialNumber);
postMethod.addParameter("name", "" + name);
postMethod.addParameter("publicKey", "" + publicKey);
postMethod.addParameter("dateOfIssue", "" + dateOfIssue);
postMethod.addParameter("expiry", "" + expiryDate);
postMethod.addParameter("issuer", "" + issuer);
postMethod.addParameter("var", " " + var);
postMethod.addParameter("siteName", "" + siteName);
boolean requestSent = postMethod.isRequestSent();
System.out.println("Is request Sent before execute method===="+ requestSent);
try {
int returnCode = httpclient.executeMethod(postMethod);
解决方案
您需要将 SSL 证书添加到您的 java 密钥库。我假设您使用的是 Windows 机器。您将需要从命令提示符运行以下命令。
"%JAVA_HOME%\bin\keytool" -import -trustcacerts -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -storepass changeit -alias CERTIFICATE -import -file CERTIFICATE.crt
推荐阅读
- object - 将对象存储在使用构造函数创建的并发哈希图中
- react-native - 当用户在本机反应中选择任何视频时如何从 webview 获取 youtube 视频链接
- python - 需要特定命令才能从 df 命令获取特定值
- character-encoding - 使用 std::filesystem::path 处理 std::string/std::wstring 的跨平台方法
- javascript - 如何在不丢失任何插入(div)数据的情况下重新加载页面
- html - 如何设置BootStrap Navbar on page right dropdown width只占用必要的空间?
- javascript - 如何用包含 TypeScript 中较新对象的数组替换对象数组?
- kubernetes - 有没有办法只增加 statefulset 的副本而不减少副本?
- python - 如何使用 BeautifulSoup 查找 html 类名?
- javascript - 发布仅具有非捆绑依赖项的 NPM 包