【发布时间】:2011-06-23 16:28:58
【问题描述】:
我在尝试使用 HttpClient 调用使用自签名证书的 https 站点时有点困惑。我有如下代码,它使我能够拨打电话,但随后我收到javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found 之类的错误我已经从我的网络浏览器下载了证书并且知道我可以将其导入密钥库但我宁愿只是把它进入代码并以这种方式使用它,有没有办法做到这一点?
HttpClient client = new HttpClient();
EasySSLProtocolSocketFactory easySSLProtocolSocketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", easySSLProtocolSocketFactory,
443);
Protocol.registerProtocol("https", https);
BufferedReader br = null;
String responseString = "";
GetMethod method = new GetMethod(path);
int returnCode = client.executeMethod(method);
【问题讨论】:
-
你到底为什么要把它放到代码中?当服务器证书过期并获得新证书时会发生什么?不要这样做。
标签: java ssl https httpclient