1
我已經創建了自己的SSLSocketFactory在this question面臨類轉換誤差兩個包
private SSLSocketFactory newSslSocketFactory() {
try {
// Get an instance of the Bouncy Castle KeyStore format
KeyStore trusted = KeyStore.getInstance("BKS");
// Get theraw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
Context context = this.activity;
Resources _resources = context.getResources();
InputStream in = _resources.openRawResource(R.raw.mystore);
try {
// Initialize the keystore with the provided trusted certificates
// Also provide the password of the keystore
trusted.load(in, "mypassword".toCharArray());
} finally {
in.close();
}
// Pass the keystore to the SSLSocketFactory. The factory is responsible
// for the verification of the server certificate.
SSLSocketFactory sf = new SSLSocketFactory(trusted);
// Hostname verification from certificate
sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
解釋之間其實我需要在連接之前設置此SSLSocketFactory
上HttpsURLConnection
。但是當我試圖通過調用
(HttpsURLConnection)connection.setSSLSocketFactory(trusted);
在這一點上,以將其放置在HttpsURLConnection
現在面臨2包org.apache.http.conn.ssl.SSLSocketFactory
和javax.net.ssl.SSLSocketFactory
之間投類錯誤。
如何解決這個問題?
請發佈異常的完整堆棧跟蹤。 –