我在php中实现了一个web服务器并连接到一个Android应用程序,我使用SSLSocketFactory所以我现在对SSLSocketFactory的静态选项之间的区别:
STRICT_HOSTNAME_VERIFIER
BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
ALLOW_ALL__HOSTNAME_VERIFIER
DefaultHttpClient ret = null;
//SETS UP PARAMETERS
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
params.setBooleanParameter("http.protocol.expect-continue", false);
//REGISTERS SCHEMES FOR BOTH HTTP AND HTTPS
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
final SSLSocketFactory sslSocketFactory = new MySSLSocketFactory(sslContext);
//final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sslSocketFactory, 443));
ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
return ret = new DefaultHttpClient(manager, params);