我想用证书连接到 SSL 认证的服务器。
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.params.BasicHttpParams;
[...]
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory sslSocketFactory = new SSLSocketFactory( keyStore, profile.getIdentityPassPhrase(), trustStore );
sslSocketFactory.setHostnameVerifier( new AllowAllHostnameVerifier() );
registry.register( new Scheme( "http", PlainSocketFactory.getSocketFactory(), 80) );
registry.register( new Scheme( "https", sslSocketFactory, 443 ) );
// Create a new HttpClient and Post Header
HttpParams httpParams = new BasicHttpParams();
httpParams.setBooleanParameter( "http.protocol.expect-continue", true );
HttpProtocolParams.setVersion( httpParams, HTTP_VERSION );
HttpProtocolParams.setContentCharset( httpParams, CONTENT_CHARSET );
HttpConnectionParams.setConnectionTimeout( httpParams, TIMEOUT_MILLISEC );
HttpConnectionParams.setSoTimeout( httpParams, TIMEOUT_MILLISEC );
httpClient = new DefaultHttpClient( new ThreadSafeClientConnManager( httpParams, registry ), httpParams );
在 Android 4.2.2(及更低版本)中,它运行良好。但在 Android 4.3 上它会抛出错误消息
javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
错误在哪里?为什么它适用于 API 17 及更低版本,但不适用于 API 18?
编辑在执行 //execute//-function 时在 HttpClient-class (org.apache.http.client) 中引发异常。这些功能在 4.3 中发生了什么变化,但在 4.2.2 中没有?Android GIT 表示没有重要的变化:https ://android.googlesource.com/platform/external/apache-http/