java httpclient在glassfish servlet中发布到https时出现“SSL证书错误”
我已经用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
有什么问题吗
# 1 楼答案
我通过在glassfish
domain.xml
中添加一些配置修复了这一问题:如果有人遇到同样的问题,发布这篇文章可能会有所帮助
请注意
changeit
是glassfish密钥库的默认密码