SSLSocketFactory的静态变量之间的差异

时间:2015-05-14 22:58:13

标签: php android

我在php中实现了一个web服务器并连接到一个Android应用程序,我使用SSLSocketFactory所以我现在对SSLSocketFactory的静态选项之间的区别:

  1. STRICT_HOSTNAME_VERIFIER

  2. BROWSER_COMPATIBLE_HOSTNAME_VERIFIER

  3. 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);
    

0 个答案:

没有答案