本文整理匯總了Java中org.apache.http.conn.params.ConnManagerParams.setTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnManagerParams.setTimeout方法的具體用法?Java ConnManagerParams.setTimeout怎麽用?Java ConnManagerParams.setTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.conn.params.ConnManagerParams
的用法示例。
在下文中一共展示了ConnManagerParams.setTimeout方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的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);
}
示例2: a
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static b a(String str) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, str);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
ConnManagerParams.setTimeout(basicHttpParams, 60000);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
Security.setProperty("networkaddress.cache.ttl", "-1");
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return new b(threadSafeClientConnManager, basicHttpParams);
}
示例3: createHttpParams
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private HttpParams createHttpParams() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(params, false);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(3));
ConnManagerParams.setMaxTotalConnections(params, 3);
ConnManagerParams.setTimeout(params, 1000);
HttpConnectionParams.setConnectionTimeout(params, 30000);
HttpConnectionParams.setSoTimeout(params, 30000);
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSocketBufferSize(params, 8192);
HttpClientParams.setRedirecting(params, false);
return params;
}
示例4: getHttpClient
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public synchronized static DefaultHttpClient getHttpClient() {
try {
HttpParams params = new BasicHttpParams();
// 設置一些基本參數
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
// 超時設置
// 從連接池中取連接的超時時間
ConnManagerParams.setTimeout(params, 10000); // 連接超時
HttpConnectionParams.setConnectionTimeout(params, 10000); // 請求超時
HttpConnectionParams.setSoTimeout(params, 30000);
SchemeRegistry registry = new SchemeRegistry();
Scheme sch1 = new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80);
registry.register(sch1);
// 使用線程安全的連接管理來創建HttpClient
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
params, registry);
mHttpClient = new DefaultHttpClient(conMgr, params);
} catch (Exception e) {
e.printStackTrace();
}
return mHttpClient;
}
示例5: createHttpParams
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static HttpParams createHttpParams() {
final HttpParams params = new BasicHttpParams();
// 設置是否啟用舊連接檢查,默認是開啟的。關閉這個舊連接檢查可以提高一點點性能,但是增加了I/O錯誤的風險(當服務端關閉連接時)。
// 開啟這個選項則在每次使用老的連接之前都會檢查連接是否可用,這個耗時大概在15-30ms之間
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);// 設置鏈接超時時間
HttpConnectionParams.setSoTimeout(params, TIMEOUT);// 設置socket超時時間
HttpConnectionParams.setSocketBufferSize(params, SOCKET_BUFFER_SIZE);// 設置緩存大小
HttpConnectionParams.setTcpNoDelay(params, true);// 是否不使用延遲發送(true為不延遲)
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // 設置協議版本
HttpProtocolParams.setUseExpectContinue(params, true);// 設置異常處理機製
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);// 設置編碼
HttpClientParams.setRedirecting(params, false);// 設置是否采用重定向
ConnManagerParams.setTimeout(params, TIMEOUT);// 設置超時
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(MAX_CONNECTIONS));// 多線程最大連接數
ConnManagerParams.setMaxTotalConnections(params, 10); // 多線程總連接數
return params;
}
示例6: getHttpClient
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
/**
* 從可用的HttpClient池中返回一個默認10秒的HttpClient對象,該方法是同步的。
*
* @return 可用的.HttpClient對象
*/
public static synchronized HttpClient getHttpClient() {
if (null == customerHttpClient) {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpProtocolParams.setUserAgent(params,
"Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "
+ "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
ConnManagerParams.setTimeout(params, 10000);
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
customerHttpClient = new DefaultHttpClient(conMgr, params);
}
return customerHttpClient;
}
示例7: AsyncHttpClient
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public AsyncHttpClient(SchemeRegistry schemeregistry)
{
a = 10;
b = 10000;
h = true;
BasicHttpParams basichttpparams = new BasicHttpParams();
ConnManagerParams.setTimeout(basichttpparams, b);
ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(a));
ConnManagerParams.setMaxTotalConnections(basichttpparams, 10);
HttpConnectionParams.setSoTimeout(basichttpparams, b);
HttpConnectionParams.setConnectionTimeout(basichttpparams, b);
HttpConnectionParams.setTcpNoDelay(basichttpparams, true);
HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192);
HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
ThreadSafeClientConnManager threadsafeclientconnmanager = new ThreadSafeClientConnManager(basichttpparams, schemeregistry);
e = getDefaultThreadPool();
f = new WeakHashMap();
g = new HashMap();
d = new SyncBasicHttpContext(new BasicHttpContext());
c = new DefaultHttpClient(threadsafeclientconnmanager, basichttpparams);
c.addRequestInterceptor(new a(this));
c.addResponseInterceptor(new b(this));
c.addRequestInterceptor(new c(this), 0);
c.setHttpRequestRetryHandler(new z(5, 1500));
}
示例8: getHttpClient
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public synchronized HttpClient getHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
// 設置連接管理器的超時
ConnManagerParams.setTimeout(params, 10000);
// 設置連接超時
HttpConnectionParams.setConnectionTimeout(params, 10000);
// 設置socket超時
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry schReg = new SchemeRegistry();
// 設置https的支持
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
//設置HTTP支持
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager conManager = new ThreadSafeClientConnManager(params, schReg);
HttpClient httpClient = new DefaultHttpClient(conManager, params);
return httpClient;
}
示例9: HTTPClientManager
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private HTTPClientManager() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
ConnManagerParams.setTimeout(params, 30000);
params.setBooleanParameter("http.protocol.expect-continue", false);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
SSLSocketFactory sslSocketFactory;
try {
registry.register(new Scheme("https", NoCertSSLSocketFactory.createDefault(), 443));
} catch (Exception e) {
Log.e("MCPE_ssl", "Couldn\\'t create SSLSocketFactory");
}
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, registry);
this.mHTTPClient = new DefaultHttpClient(manager, params);
}
示例10: getHttpClient
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static HttpClient getHttpClient() {
HttpClient httpClient = new DefaultHttpClient();
HttpParams httpParams = httpClient.getParams();
/*
* set connection and socket timeout intervals
*/
HttpConnectionParams.setConnectionTimeout(httpParams,
REGISTRATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, WAIT_TIMEOUT);
ConnManagerParams.setTimeout(httpParams, WAIT_TIMEOUT);
/*
* by default it is undesirable to follow redirects as these contain
* data needed in the discovery process
*/
httpParams.setBooleanParameter("http.protocol.handle-redirects", false);
return httpClient;
}
示例11: getHttpClient
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static synchronized HttpClient getHttpClient() {
if (customHttpClient == null) {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
ConnManagerParams.setTimeout(params, 1000);
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http",
PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager conMgr = new
ThreadSafeClientConnManager(params, schReg);
customHttpClient = new DefaultHttpClient(conMgr, params);
}
return customHttpClient;
}
示例12: createConnectionManager
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static synchronized ClientConnectionManager createConnectionManager() {
if (connectionManager != null) {
return connectionManager;
}
// Create and initialize scheme registry
SchemeRegistry schemeRegistry = new SchemeRegistry();
Scheme httpScheme = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
//Scheme httpsScheme = new Scheme("https", SSLSocketFactory.getSocketFactory(), 443);
Scheme httpsScheme = new Scheme("https", LibSSLSocketFactory.getSocketFactory(), 443);
schemeRegistry.register(httpScheme);
schemeRegistry.register(httpsScheme);
HttpParams managerParams = new BasicHttpParams();
//設置連接池允許的最大連接數
ConnManagerParams.setMaxTotalConnections(managerParams, Constants.CONNECTION_POOL_SIZE);
//設置連接池連接超時時間
ConnManagerParams.setTimeout(managerParams, Constants.CONNECTION_TIME_OUT);
connectionManager = new ThreadSafeClientConnManager(managerParams, schemeRegistry);
return connectionManager;
}
示例13: createConnectionManager
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static synchronized ClientConnectionManager createConnectionManager() {
if (connectionManager != null) {
return connectionManager;
}
// Create and initialize scheme registry
SchemeRegistry schemeRegistry = new SchemeRegistry();
Scheme httpScheme = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
//Scheme httpsScheme = new Scheme("https", SSLSocketFactory.getSocketFactory(), 443);
Scheme httpsScheme = new Scheme("https", YiBoSSLSocketFactory.getSocketFactory(), 443);
schemeRegistry.register(httpScheme);
schemeRegistry.register(httpsScheme);
HttpParams managerParams = new BasicHttpParams();
//設置連接池允許的最大連接數
ConnManagerParams.setMaxTotalConnections(managerParams, Constants.CONNECTION_POOL_SIZE);
//設置連接池連接超時時間
ConnManagerParams.setTimeout(managerParams, Constants.CONNECTION_TIME_OUT);
connectionManager = new ThreadSafeClientConnManager(managerParams, schemeRegistry);
return connectionManager;
}
示例14: createHttpParams
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static final HttpParams createHttpParams() {
final HttpParams params = new BasicHttpParams();
HttpProtocolParams.setUseExpectContinue(params, false);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
ConnManagerParams.setTimeout(params, NetworkHelper.SOCKET_TIMEOUT_MS);
HttpConnectionParams.setConnectionTimeout(params,
NetworkHelper.CONNECTION_TIMEOUT_MS);
HttpConnectionParams.setSoTimeout(params,
NetworkHelper.SOCKET_TIMEOUT_MS);
ConnManagerParams.setMaxConnectionsPerRoute(params,
new ConnPerRouteBean(NetworkHelper.MAX_TOTAL_CONNECTIONS));
ConnManagerParams.setMaxTotalConnections(params,
NetworkHelper.MAX_TOTAL_CONNECTIONS);
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSocketBufferSize(params,
NetworkHelper.SOCKET_BUFFER_SIZE);
HttpClientParams.setRedirecting(params, false);
HttpProtocolParams.setUserAgent(params, "FanFou for Android/"
+ AppContext.appVersionName);
return params;
}
示例15: configTimeout
import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public HttpUtils configTimeout(int timeout) {
final HttpParams httpParams = this.httpClient.getParams();
ConnManagerParams.setTimeout(httpParams, timeout);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
return this;
}