3
我有下面的代碼有問題...javax.net.ssl.SSLException:SSLSocketFactory的是空
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();
我試圖設置信任存儲,密鑰存儲和使用System.setProperty(key,value)
SSL上下文的其他屬性方法,但我收到以下錯誤。
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.
有人可以幫我解決這個問題。
你用什麼代碼/設置來獲取? – Bruno
@Bruno:現在檢查代碼。我編輯了這篇文章。 –
在設置屬性之前,您以前是否調用過'SSLSocketFactory.getDefault()'? – EJP