當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。