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); }
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); }
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; }
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; }
/** * Returns the one <code>WebServiceUtil</code> instance * @return the one <code>WebServiceUtil</code> instance */ public static WebServiceUtil getInstance() { // This needs to be here instead of in the constructor because // it uses classes that are in the AndroidSDK and thus would // cause Stub! errors when running the component descriptor. synchronized(httpClientSynchronizer) { if (httpClient == null) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); BasicHttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); ConnManagerParams.setMaxTotalConnections(params, 20); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); WebServiceUtil.httpClient = new DefaultHttpClient(manager, params); } } return INSTANCE; }
private DefaultHttpClient createHttpClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); HttpConnectionParams.setConnectionTimeout(params, CONNETED_TIMEOUT * 1000); HttpConnectionParams.setSoTimeout(params, CONNETED_TIMEOUT * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); ConnManagerParams.setMaxTotalConnections(params, 4); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory .getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connMgr = new ThreadSafeClientConnManager( params, schReg); return new DefaultHttpClient(connMgr, params); }
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; }
private static DefaultHttpClient getClient() { if (client == null || !REUSE_CLIENT) { AQUtility.debug("creating http client"); HttpParams httpParams = new BasicHttpParams(); //httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(httpParams, NET_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, NET_TIMEOUT); //ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(NETWORK_POOL)); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25)); //Added this line to avoid issue at: http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt HttpConnectionParams.setSocketBufferSize(httpParams, 8192); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443)); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, registry); client = new DefaultHttpClient(cm, httpParams); } return client; }
/** * 从可用的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; }
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); }
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)); }
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; }
public RESTMusicService() { // Create and initialize default HTTP parameters HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 20); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20)); HttpConnectionParams.setConnectionTimeout(params, SOCKET_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_DEFAULT); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(params, false); // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", createSSLSocketFactory(), 443)); // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. connManager = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new DefaultHttpClient(connManager, params); }
public void init() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory .getSocketFactory(), 80)); HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 10); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new DefaultHttpClient(cm, params); // 重试 // httpClient.setHttpRequestRetryHandler(new // DefaultHttpRequestRetryHandler(3, false)); // 超时设置 // httpClient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, // 10000); // httpClient.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, // 10000); httpClient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true); threadNum = 10; execService = Executors.newFixedThreadPool(threadNum); destroy = false; }
public AndroidDispatchServiceAsync() { // Create and initialize HTTP parameters HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 100); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory .getSocketFactory(), 80)); // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = HttpUtils.getHttpClient(cm); cookieStore = new CustomCookieStore(); }
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; }
public static HttpClient generateHttpClient(final int maxTotalConnections, final int maxTotalConnectionsPerRoute, int connTimeout) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute route) { return maxTotalConnectionsPerRoute; } }); HttpConnectionParams .setConnectionTimeout(params, connTimeout); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory. ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(conMgr, params); }
public static HttpClient generateHttpClient(final int maxTotalConnections, final int maxTotalConnectionsPerRoute, int connTimeout) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute route) { return maxTotalConnectionsPerRoute; } }); HttpConnectionParams .setConnectionTimeout(params, connTimeout); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(conMgr, params); }
private ConnectionHelper() { HttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(httpParams, MAX_TOTAL_CONNECTIONS); ConnPerRouteBean connPerRoute = new ConnPerRouteBean( MAX_CONNECTIONS_PER_HOST); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(httpParams, false); SchemeRegistry reg = new SchemeRegistry(); reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager( httpParams, reg); HttpConnectionParams.setConnectionTimeout(httpParams, CON_TIME_OUT_MS); HttpConnectionParams.setSoTimeout(httpParams, SO_TIME_OUT_MS); HttpClientParams.setCookiePolicy(httpParams, CookiePolicy.BROWSER_COMPATIBILITY); httpClient = new DefaultHttpClient(connectionManager, httpParams); }
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; }
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; }
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; }
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; }
public HttpResponse postMessage(MultipartEntity entity, String board) { HttpPost p = new HttpPost(String.format(DobroConstants.POST_NEW, board)); final HttpParams params = new BasicHttpParams(); HttpClientParams.setRedirecting(params, false); ConnManagerParams.setTimeout(params, 20000); HttpConnectionParams.setSoTimeout(params, 20000); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 8192); p.setParams(params); p.setEntity(entity); try { HttpResponse r = m_httpclient.execute(p, m_http_context); p.abort(); return r; } catch (IOException e) { e.printStackTrace(); } return null; }
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; }
/** * Constructs a new DefaultHttpClient with a default 30 second timeout. */ public static DefaultHttpClient createHttpClient() { DefaultHttpClient client = new DefaultHttpClient(); final HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT); return client; }
public void setMaxConnections(int maxConnections) { if (maxConnections < 1) { maxConnections = 10; } this.maxConnections = maxConnections; ConnManagerParams.setMaxConnectionsPerRoute(this.httpClient.getParams(), new ConnPerRouteBean(this.maxConnections)); }
public void setConnectTimeout(int value) { if (value < 1000) { value = 10000; } this.connectTimeout = value; HttpParams httpParams = this.httpClient.getParams(); ConnManagerParams.setTimeout(httpParams, (long) this.connectTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, this.connectTimeout); }
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; }
/** * Sets maximum limit of parallel connections * * @param maxConnections maximum parallel connections, must be at least 1 */ public void setMaxConnections(int maxConnections) { if (maxConnections < 1) maxConnections = DEFAULT_MAX_CONNECTIONS; this.maxConnections = maxConnections; final HttpParams httpParams = this.httpClient.getParams(); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(this.maxConnections)); }
/** * Set the connection and socket timeout. By default, 10 seconds. * * @param timeout the connect/socket timeout in milliseconds, at least 1 second */ public void setTimeout(int timeout) { if (timeout < 1000) timeout = DEFAULT_SOCKET_TIMEOUT; this.timeout = timeout; final HttpParams httpParams = this.httpClient.getParams(); ConnManagerParams.setTimeout(httpParams, this.timeout); HttpConnectionParams.setSoTimeout(httpParams, this.timeout); HttpConnectionParams.setConnectionTimeout(httpParams, this.timeout); }