javax.net.ssl.SSLException:SSLSocketFactory为空 [英] javax.net.ssl.SSLException: SSLSocketFactory is null

查看:538
本文介绍了javax.net.ssl.SSLException:SSLSocketFactory为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下代码有疑问...

I have a problem with the following code...

System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperty("javax.net.ssl.trustStoreType", "jks");
System.setProperty("javax.net.ssl.keyStore","C:\\ClientKeyStore\\ClientKeyStore.p12");
System.setProperty("javax.net.ssl.trustStore","C:\\ClientKeyStore\\ClientKeyStore.keystore");
System.setProperty("javax.net.debug", "ssl");
System.setProperty("javax.net.ssl.keyStorePassword", "keystorepass");
System.setProperty("javax.net.ssl.trustStorePassword", "truststorepass");

SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
URL url = new URL("https://url.com");
HttpsURLConnection httpCon = (HttpsURLConnection) url.openConnection();
httpCon.setSSLSocketFactory(sslsocketfactory);
OutputStream out=httpCon.getOutputStream();

我尝试使用<$ c $设置SSL上下文的信任库,密钥库和其他属性c> System.setProperty(key,value)方法,但出现以下错误。

I tried to set the trust store, keystore and other properties of SSL context using the System.setProperty(key,value) method, but I'm getting the following error.

javax.net.ssl.SSLException: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to create a socket and javax.net.ssl.* properties are not set.

有人可以帮助我解决这个问题。

Could someone please help me with this problem.

推荐答案

即使在Windows上,也可以尝试路径的正斜杠:

You can try forward slashes for the paths even on windows:

System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperty("javax.net.ssl.trustStoreType", "jks");
System.setProperty("javax.net.ssl.keyStore","C:/ClientKeyStore/ClientKeyStore.p12");
System.setProperty("javax.net.ssl.trustStore","C:/ClientKeyStore/ClientKeyStore.keystore");
System.setProperty("javax.net.debug", "ssl");
System.setProperty("javax.net.ssl.keyStorePassword", "keystorepass");
System.setProperty("javax.net.ssl.trustStorePassword", "truststorepass");


SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();

这是您的所有代码吗?您的属性看起来不错,我能够使用您的示例创建套接字工厂。

Is this all your code? Your properties look fine and I was able to use your example to create a socket factory.

这篇关于javax.net.ssl.SSLException:SSLSocketFactory为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆