httpclinet:4.3.1
jdk:1.6
tomcat:6
https://blog.csdn.net/zhongming_software/article/details/8592331 按照该文章所写代码会报如下错误
参照http://blog.51cto.com/2074199/2088928,然后将sslcontext改成如下代码
InputStream ksis = new FileInputStream(new File("client.p12的路径"));
InputStream tsis = new FileInputStream(new File("server.jks的路径"));
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(ksis, "storepass密码".toCharArray());
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(tsis, "storepass密码".toCharArray());
sslcontext = SSLContexts.custom().loadKeyMaterial(ks, "keypass".toCharArray()).loadTrustMaterial(ts, new TrustSelfSignedStrategy()).build();
loadKeyMaterial()重载方法是加载客户端证书用的
loadTrustMaterial()重载方法是加载服务器端相关信息用的(我们就是使用 new TrustSelfSignedStrategy()方法自己实现了一个信任策略,不对服务器端的证书进行校验)
原文地址:http://blog.51cto.com/2074199/2121232