gpt4 book ai didi

java - 使用 httpClient 和 cert.em 的 https post 请求

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:36 24 4
gpt4 key购买 nike

我有一段代码将负载发送到 https 端点(或应该)。我还有一个 .pem 格式的 CA 链,这就是我在代码中尝试添加的方式,使用它来执行 POST。

HttpClient client = new HttpClient();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonString = gson.toJson(parentData);
Properties systemProps = System.getProperties();
systemProps.put( "javax.net.ssl.trustStore", "/Users/kaulk/Downloads/djca-2048.pem");
systemProps.put("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStoreType","pkcs12");
System.setProperties(systemProps);
PostMethod method = new PostMethod("https://beta.fcm.fint.xxx.net/notify/BuildNotification");
StringRequestEntity requestEntity = new StringRequestEntity(
jsonString,
"application/json",
"UTF-8");
method.setRequestEntity(requestEntity);
int statusCode = client.executeMethod(method);

但失败并出现错误:

Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl) at java.security.Provider$Service.newInstance(Provider.java:1245) at sun.security.jca.GetInstance.getInstance(GetInstance.java:220) at sun.security.jca.GetInstance.getInstance(GetInstance.java:147) at javax.net.ssl.SSLContext.getInstance(SSLContext.java:125) at javax.net.ssl.SSLContext.getDefault(SSLContext.java:68) at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:102) ... 22 more Caused by: java.io.IOException: Invalid keystore format

有什么原因吗?

最佳答案

根据有关 SSL 属性的文档

javax.net.ssl.trustStoreType - (Optional) For Java keystore file format, this property has the value jks (or JKS). You do not normally specify this property, because its default value is already jks.

尝试设置 javax.net.ssl.trustStoreType

您收到的异常通常是由于潜在错误而引发的。

这些设置还将帮助您获取更多信息以进行故障排除-Djavax.net.debug=ssl,或至少 -Djavax.net.debug=ssl,keymanager

storeType要根据导入的证书文件有用的帖子 - Java Exception on SSLSocket creation

关于java - 使用 httpClient 和 cert.em 的 https post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30732280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com