2006/06/21 | 用keytool添加证书,取得https返回的信息
类别(Programme) | 评论(0) | 阅读(257) | 发表于 16:34
做在线支付,需要从银行的https协议取得一些返回的信息。
如果truststore里没有所需的证书,那么会蹦出异常: No trusted certificate found

这个时候需要将银行的证书添加到truststore,我们可以用keytool来完成。keytool是jdk本身自带的证书工具,调用很方便。

首先,取得证书。具体做法:到银行的https协议的页面,点击右下角小锁的标志,选择"安装证书",将证书保存为xxx.cer文件。

然后,将证书添加到truststore,具体做法:命令行
keytool -import -alias bank -file xxx.cer -keystore cacerts

最后,在程序里加上一句 System.setProperty("javax.net.ssl.trustStore", "cacerts");

剩下该怎么读https返回的内容就怎么读吧~~

如果服务器对useragent有限制,就模拟一下ie/mozila就行了,方法如下:
System.getProperties().setProperty("httpclient.useragent", "Mozilla/4.0");
0

评论Comments

日志分类
首页[50]
MyBlog[11]
WebService[3]
Programme[19]
Pastime[17]