【问题标题】:httpclient got a "SSL certificate error" when post to https in glassfish servlethttpclient 在 glassfish servlet 中发布到 https 时出现“SSL 证书错误”
【发布时间】:2015-05-29 07:48:32
【问题描述】:

我已经用 apache httpClient 写了一个静态 post 方法:

public class HttpPost {
    public static HttpPostResult post(String url, String xml) throws IOException {
        Logger.getAnonymousLogger().log(Level.INFO, url + "|" + xml);
        HttpClient httpClient = new HttpClient();
        HttpPostResult httpPostResult = new HttpPostResult();
        PostMethod postMethod = new PostMethod(url);
        StringRequestEntity stringRequestEntity = new StringRequestEntity(xml,"xml","utf-8");
        postMethod.setRequestEntity(stringRequestEntity);
        httpClient.executeMethod(postMethod);
        httpPostResult.setStatus(postMethod.getStatusCode());
        httpPostResult.setResponseStr(postMethod.getResponseBodyAsString());
        return httpPostResult;
    }
}

这个方法在我单独测试它时工作得很好,但是一旦我将它构建到一个 maven 依赖项并将它包含在一个 http servlet 中,它就不起作用并且响应字符串变成:

<html>
<head><title>400 The SSL certificate error</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The SSL certificate error</center>
<hr><center>nginx</center>
</body>
</html>

似乎远程主机正在使用 nginx,我猜可能发生了一些 SSL 信任问题,但远程主机是受信任的(由可信机构签名的 CA)它是 https://api.mch.weixin.qq.com/pay/orderquery

应该是什么问题?

【问题讨论】:

    标签: java maven servlets ssl glassfish


    【解决方案1】:

    我通过在 glassfish domain.xml 中添加一些配置来解决此问题:

    <jvm-options>-Djavax.net.ssl.keyStorePassword=changeit</jvm-options>
    <jvm-options>-Djavax.net.ssl.trustStorePassword=changeit</jvm-options>
    

    发布此内容可能对遇到相同问题的人有所帮助。

    请注意,changeit 是 glassfish 密钥库的默认密码。

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      相关资源
      最近更新 更多