本文整理匯總了Java中org.apache.http.conn.scheme.SocketFactory.setHostnameVerifier方法的典型用法代碼示例。如果您正苦於以下問題:Java SocketFactory.setHostnameVerifier方法的具體用法?Java SocketFactory.setHostnameVerifier怎麽用?Java SocketFactory.setHostnameVerifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.conn.scheme.SocketFactory
的用法示例。
在下文中一共展示了SocketFactory.setHostnameVerifier方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSSLHttpClient
import org.apache.http.conn.scheme.SocketFactory; //導入方法依賴的package包/類
private HttpClient getSSLHttpClient() throws Throwable {
KeyStore instance = KeyStore.getInstance(KeyStore.getDefaultType());
instance.load(null, null);
SocketFactory sSLSocketFactoryEx = new SSLSocketFactoryEx(instance);
sSLSocketFactoryEx.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme(b.a, sSLSocketFactoryEx, WebSocket.DEFAULT_WSS_PORT));
return new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams,
schemeRegistry), basicHttpParams);
}
示例2: a
import org.apache.http.conn.scheme.SocketFactory; //導入方法依賴的package包/類
public static b a() {
if (b == null) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
ConnManagerParams.setTimeout(basicHttpParams, 1000);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, a);
try {
SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(scheme);
schemeRegistry.register(scheme2);
b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
} catch (Exception e) {
b = new b(basicHttpParams);
}
}
return b;
}
示例3: getHttpClient
import org.apache.http.conn.scheme.SocketFactory; //導入方法依賴的package包/類
public static HttpClient getHttpClient(Context context, String str, String str2) {
OpenConfig instance;
int i;
int i2 = 0;
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
if (VERSION.SDK_INT < 16) {
try {
KeyStore instance2 = KeyStore.getInstance(KeyStore.getDefaultType());
instance2.load(null, null);
SocketFactory customSSLSocketFactory = new CustomSSLSocketFactory(instance2);
customSSLSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, customSSLSocketFactory, 443));
} catch (Exception e) {
schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, SSLSocketFactory.getSocketFactory(), 443));
}
} else {
schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, SSLSocketFactory.getSocketFactory(), 443));
}
HttpParams basicHttpParams = new BasicHttpParams();
if (context != null) {
instance = OpenConfig.getInstance(context, str);
} else {
instance = null;
}
if (instance != null) {
i = instance.getInt("Common_HttpConnectionTimeout");
i2 = instance.getInt("Common_SocketConnectionTimeout");
} else {
i = 0;
}
if (i == 0) {
i = LetvConstant.WIDGET_UPDATE_UI_TIME;
}
if (i2 == 0) {
i2 = 30000;
}
HttpConnectionParams.setConnectionTimeout(basicHttpParams, i);
HttpConnectionParams.setSoTimeout(basicHttpParams, i2);
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
HttpProtocolParams.setUserAgent(basicHttpParams, "AndroidSDK_" + VERSION.SDK + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + Build.DEVICE + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + VERSION.RELEASE);
HttpClient defaultHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
NetworkProxy proxy = getProxy(context);
if (proxy != null) {
defaultHttpClient.getParams().setParameter("http.route.default-proxy", new HttpHost(proxy.host, proxy.port));
}
return defaultHttpClient;
}
示例4: getHttpClient
import org.apache.http.conn.scheme.SocketFactory; //導入方法依賴的package包/類
public static HttpClient getHttpClient(Context context, String str, String str2) {
OpenConfig instance;
int i;
int i2 = 0;
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
if (VERSION.SDK_INT < 16) {
try {
KeyStore instance2 = KeyStore.getInstance(KeyStore.getDefaultType());
instance2.load(null, null);
SocketFactory customSSLSocketFactory = new CustomSSLSocketFactory(instance2);
customSSLSocketFactory.setHostnameVerifier(SSLSocketFactory
.STRICT_HOSTNAME_VERIFIER);
schemeRegistry.register(new Scheme(b.a, customSSLSocketFactory, WebSocket
.DEFAULT_WSS_PORT));
} catch (Exception e) {
schemeRegistry.register(new Scheme(b.a, SSLSocketFactory.getSocketFactory(),
WebSocket.DEFAULT_WSS_PORT));
}
} else {
schemeRegistry.register(new Scheme(b.a, SSLSocketFactory.getSocketFactory(),
WebSocket.DEFAULT_WSS_PORT));
}
HttpParams basicHttpParams = new BasicHttpParams();
if (context != null) {
instance = OpenConfig.getInstance(context, str);
} else {
instance = null;
}
if (instance != null) {
i = instance.getInt("Common_HttpConnectionTimeout");
i2 = instance.getInt("Common_SocketConnectionTimeout");
} else {
i = 0;
}
if (i == 0) {
i = 15000;
}
if (i2 == 0) {
i2 = 30000;
}
HttpConnectionParams.setConnectionTimeout(basicHttpParams, i);
HttpConnectionParams.setSoTimeout(basicHttpParams, i2);
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
HttpProtocolParams.setUserAgent(basicHttpParams, "AndroidSDK_" + VERSION.SDK + "_" +
Build.DEVICE + "_" + VERSION.RELEASE);
HttpClient defaultHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager
(basicHttpParams, schemeRegistry), basicHttpParams);
NetworkProxy proxy = getProxy(context);
if (proxy != null) {
defaultHttpClient.getParams().setParameter("http.route.default-proxy", new HttpHost
(proxy.host, proxy.port));
}
return defaultHttpClient;
}