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
之间投类错误。
如何解决这个问题?
请发布异常的完整堆栈跟踪。 –