当前位置: 首页>>代码示例>>Java>>正文


Java SSLSocketFactory.setHostnameVerifier方法代码示例

本文整理汇总了Java中org.apache.http.conn.ssl.SSLSocketFactory.setHostnameVerifier方法的典型用法代码示例。如果您正苦于以下问题:Java SSLSocketFactory.setHostnameVerifier方法的具体用法?Java SSLSocketFactory.setHostnameVerifier怎么用?Java SSLSocketFactory.setHostnameVerifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.conn.ssl.SSLSocketFactory的用法示例。


在下文中一共展示了SSLSocketFactory.setHostnameVerifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNewHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private static HttpClient getNewHttpClient() { 
   try { 
       KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); 
       trustStore.load(null, null); 

       SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); 
       sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 

       HttpParams params = new BasicHttpParams(); 
       HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 
       HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); 

       SchemeRegistry registry = new SchemeRegistry(); 
       registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
       registry.register(new Scheme("https", sf, 443)); 

       ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); 

       return new DefaultHttpClient(ccm, params); 
   } catch (Exception e) { 
       return new DefaultHttpClient(); 
   } 
}
 
开发者ID:gyqGitHub,项目名称:WeiXinPayDemo,代码行数:24,代码来源:Util.java

示例2: get

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
public static HttpClient get() {
    HttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, 3000);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(30));
    ConnManagerParams.setMaxTotalConnections(httpParams, 30);
    HttpClientParams.setRedirecting(httpParams, true);
    HttpProtocolParams.setUseExpectContinue(httpParams, true);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
    HttpConnectionParams.setSoTimeout(httpParams, 2000);
    HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, sf, 443));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:26,代码来源:PoolingClientConnectionManager.java

示例3: getNewHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private static HttpClient getNewHttpClient() { 
   try { 
       KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
       trustStore.load(null, null); 

       SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
       sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

       HttpParams params = new BasicHttpParams();
       HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 
       HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); 

       SchemeRegistry registry = new SchemeRegistry(); 
       registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
       registry.register(new Scheme("https", sf, 443)); 

       ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); 

       return new DefaultHttpClient(ccm, params); 
   } catch (Exception e) {
       return new DefaultHttpClient(); 
   } 
}
 
开发者ID:cheng2016,项目名称:developNote,代码行数:24,代码来源:HttpUtil.java

示例4: getSchemeRegistry

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
public static SchemeRegistry getSchemeRegistry() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
        SSLSocketFactory sf = new SSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));
        return registry;
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:While1true,项目名称:JSSample,代码行数:21,代码来源:HttpUtils.java

示例5: getTrustAllHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private static HttpClient getTrustAllHttpClient()
{
	try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        TrustManager[] temp =new TrustManager[1];
        temp[0]=new CxfClientUtilsOld.TrustAllManager();
        sslContext.init(null, temp, null);
        
        SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext);
        sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        
        HttpClient httpClient=new DefaultHttpClient();
        ClientConnectionManager connectionManager = httpClient.getConnectionManager();
        SchemeRegistry schemeRegistry = connectionManager.getSchemeRegistry();
        schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
        return(new DefaultHttpClient(connectionManager, httpClient.getParams()));
       } catch (Exception e) {
        logger.error("Unexpected error", e);
        return(null);
       }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:22,代码来源:SendingUtils.java

示例6: createThreadSafeClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private static void createThreadSafeClient(boolean forceSecure) {
    httpClient = new DefaultHttpClient();
    ClientConnectionManager mgr = httpClient.getConnectionManager();
    HttpParams params = httpClient.getParams();
    SchemeRegistry schemeRegistry = mgr.getSchemeRegistry();

    if (forceSecure) {
        schemeRegistry.register(new Scheme("https",
                getSecureConnectionSetting(), 443));
    } else {
        HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        SSLSocketFactory socketFactory = SSLSocketFactory
                .getSocketFactory();
        socketFactory
                .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        schemeRegistry.register(new Scheme("https", socketFactory, 443));
    }

    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params,
            schemeRegistry), params);
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-follow-up,代码行数:22,代码来源:OdooSafeClient.java

示例7: ignoreSSLCertification

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
/**
 * SSL証明書のチェックを無効化します。
 * 
 * @param httpsconnection
 */
@SuppressWarnings("deprecation")
private static void ignoreSSLCertification(HttpClient httpClient) {

  try {

    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    keyStore.load(null, null);
    SSLSocketFactory sslSocketFactory = new CostomSSLSocketFactory(keyStore);

    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme scheme = new Scheme("https", sslSocketFactory, 443);
    httpClient.getConnectionManager().getSchemeRegistry().register(scheme);

  } catch (Exception e) {
    YConnectLogger.error(YHttpClient.class, e.getMessage());
    e.printStackTrace();
  }

}
 
开发者ID:yahoojapan,项目名称:yconnect-servlet-sdk,代码行数:25,代码来源:YHttpClient.java

示例8: JSONRPCHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
/**
 * Construct a JsonRPCClient with the given service uri
 * 
 * @param uri
 *            uri of the service
 */
public JSONRPCHttpClient(String uri)
{
	SSLSocketFactory allowAllsslFactory = null;
	try {
		allowAllsslFactory = new AllowAllSSLSocketFactory(null);
	} catch (Exception e) {
		e.printStackTrace();
	}
	allowAllsslFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
	// Quick ugly fix to accept ssl certificates
    
	HttpParams params = new BasicHttpParams();
	SchemeRegistry registry = new SchemeRegistry();
	registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
	registry.register(new Scheme("https", allowAllsslFactory, 443));

	ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(params, registry);
	httpClient = new DefaultHttpClient(ccm, params);
	serviceUri = uri;
}
 
开发者ID:lampmantech,项目名称:tryton_android,代码行数:27,代码来源:JSONRPCHttpClient.java

示例9: secureLoadData

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
public HttpResponse secureLoadData(String url)
        throws ClientProtocolException, IOException,
        NoSuchAlgorithmException, KeyManagementException,
        URISyntaxException, KeyStoreException, UnrecoverableKeyException {
    SSLContext ctx = SSLContext.getInstance("TLS");
    ctx.init(null, new TrustManager[] { new CustomX509TrustManager() },
            new SecureRandom());

    HttpClient client = new DefaultHttpClient();

    SSLSocketFactory ssf = new CustomSSLSocketFactory(ctx);
    ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm = client.getConnectionManager();
    SchemeRegistry sr = ccm.getSchemeRegistry();
    sr.register(new Scheme("https", ssf, 443));
    DefaultHttpClient sslClient = new DefaultHttpClient(ccm,
            client.getParams());

    HttpGet get = new HttpGet(new URI(url));
    HttpResponse response = sslClient.execute(get);

    return response;
}
 
开发者ID:patrickprn,项目名称:ninuxmobile,代码行数:24,代码来源:DataLoader.java

示例10: hostnameVerification

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
public static SSLSocketFactory hostnameVerification(Context context) {
    try {
        // Get an instance of the Bouncy Castle KeyStore format
        KeyStore trusted = KeyStore.getInstance("BKS");
        // Get the raw resource, which contains the keystore with
        // your trusted certificates (root and any intermediate certs)
        InputStream in = context.getResources().openRawResource(R.raw.safaricom_keystore);
        try {
            // Initialize the keystore with the provided trusted certificates
            // Also provide the password of the keystore
            trusted.load(in, "ch0wder1".toCharArray());
        } finally {
            in.close();
        }
        // Pass the keystore to the SSLSocketFactory. The factory is responsible
        // for the verification of the server certificate.
        SSLSocketFactory sslSocketFactory = new SSLSocketFactory(trusted);
        // Hostname verification from certificate
        // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
        sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
        return sslSocketFactory;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:IanWambai,项目名称:Chowder,代码行数:26,代码来源:ChowderUtils.java

示例11: CookieRestTemplate

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
public CookieRestTemplate() {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, false);

    //REGISTERS SCHEMES FOR BOTH HTTP AND HTTPS
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    registry.register(new Scheme("https", sslSocketFactory, 443));

    ClientConnectionManager conman = new ThreadSafeClientConnManager(params, registry);
    httpClient = new DefaultHttpClient(conman, params);
    HttpComponentsClientHttpRequestFactory hcchrf = new StatefulHttpComponentsClientHttpRequestFactory(httpClient, httpContext);
    hcchrf.setConnectTimeout(30 * 1000);
    setRequestFactory(hcchrf);
}
 
开发者ID:murielK,项目名称:AndroidWPTemplate,代码行数:22,代码来源:CookieRestTemplate.java

示例12: getNewHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private HttpClient getNewHttpClient() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new CustomSSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}
 
开发者ID:ianholing,项目名称:Crazy-wheel-godot-google-play,代码行数:24,代码来源:HttpRequester.java

示例13: getNewHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private static HttpClient getNewHttpClient() {
	try {
		KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
		trustStore.load(null, null);
		SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
		sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		HttpParams params = new BasicHttpParams();
		HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
		HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
		SchemeRegistry registry = new SchemeRegistry();
		registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
		registry.register(new Scheme("https", sf, 443));
		ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
		return new DefaultHttpClient(ccm, params);
	} catch (Exception e) {
		return new DefaultHttpClient();
	}
}
 
开发者ID:hanks-zyh,项目名称:Conquer,代码行数:19,代码来源:NetUtils.java

示例14: getNewHttpClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
private static HttpClient getNewHttpClient() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}
 
开发者ID:LightSun,项目名称:android-common-utils,代码行数:24,代码来源:WeixinUtil.java

示例15: getHttpsWildcardTolerantClient

import org.apache.http.conn.ssl.SSLSocketFactory; //导入方法依赖的package包/类
/**
 * Gets a DefaultHttpClient that's tolerant of wildcard matches.
 * 
 * @param httpParams HTTP Parameters for a DefaultHttpClient
 * 
 * @return DefaultHttpClient that's tolerant of wildcard matches.
 */
public static DefaultHttpClient getHttpsWildcardTolerantClient(final HttpParams httpParams)
{
    DefaultHttpClient client = new DefaultHttpClient(httpParams);
    
    SSLSocketFactory sslSocketFactory =
        (SSLSocketFactory) client 
        .getConnectionManager()
        .getSchemeRegistry()
        .getScheme("https") 
        .getSocketFactory();
    
    final X509HostnameVerifier delegate = sslSocketFactory.getHostnameVerifier();
    
    if (!(delegate instanceof HttpsWildcardVerifier))
    { 
        sslSocketFactory.setHostnameVerifier(new HttpsWildcardVerifier(delegate)); 
    } 
    
    return client;          
}
 
开发者ID:nicjansma,项目名称:com.nicjansma.library,代码行数:28,代码来源:HttpsWildcardVerifier.java


注:本文中的org.apache.http.conn.ssl.SSLSocketFactory.setHostnameVerifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。