List of usage examples for org.apache.http.params HttpProtocolParams setVersion
public static void setVersion(HttpParams httpParams, ProtocolVersion protocolVersion)
From source file:com.ninja.examples.utility.net.APIRequest.java
public static DefaultHttpClient getClient() { if (httpclient == null) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setUseExpectContinue(params, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); HttpConnectionParams.setConnectionTimeout(params, WS_TIMEOUT); HttpConnectionParams.setSoTimeout(params, WS_TIMEOUT); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); httpclient = new DefaultHttpClient(manager, params); httpclient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() { public long getKeepAliveDuration(HttpResponse response, HttpContext context) { return 50; }/*from w ww .j a v a 2 s.c o m*/ }); } return httpclient; }
From source file:com.healthcit.analytics.dao.HttpClientWrapper.java
/** * @return The unique instance of this class. *///from www . j av a 2 s. com public static synchronized HttpClientWrapper getHttpClient() { if (httpClient == null) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new HttpClientWrapper(cm, params); } return httpClient; }
From source file:ru.elifantiev.yandex.SSLHttpClientFactory.java
public static HttpClient getNewHttpClient() { try {// w w w . j a v a 2 s.c om KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new YandexSSLSocketFactory(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(); } }
From source file:com.deliciousdroid.client.HttpClientFactory.java
public static HttpClient getThreadSafeClient() { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 100); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager mgr = new ThreadSafeClientConnManager(params, schemeRegistry); HttpClient client = new DefaultHttpClient(mgr, params); return client; }
From source file:com.nebkat.junglist.bot.http.ConnectionManager.java
public static HttpClient getHttpClient() { if (sHttpClient == null) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, new EasySSLSocketFactory())); HttpParams params = new BasicHttpParams(); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry); connectionManager.setDefaultMaxPerRoute(30); connectionManager.setMaxTotal(30); sHttpClient = new DefaultHttpClient(connectionManager, params); ((DefaultHttpClient) sHttpClient).addResponseInterceptor((response, context) -> { if (response.containsHeader("Location")) { context.setAttribute(REDIRECTED, true); }/*from www. j a va2s .co m*/ }); } return sHttpClient; }
From source file:com.subgraph.vega.internal.http.requests.BasicHttpClientFactory.java
private static HttpParams createHttpParams() { final HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); return params; }
From source file:jacky.song.android.util.net.HttpConnector.java
private static HttpClient createClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params, true); ConnManagerParams.setTimeout(params, 1000); HttpConnectionParams.setConnectionTimeout(params, 2000); HttpConnectionParams.setSoTimeout(params, 4000); 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); return new DefaultHttpClient(conMgr, params); }
From source file:org.ale.scanner.zotero.web.HttpsClient.java
public static HttpParams setupHttpParams() { HttpParams params = new BasicHttpParams(); // Protocol Parameters HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); HttpProtocolParams.setUseExpectContinue(params, false); HttpProtocolParams.setUserAgent(params, USER_AGENT); // Connection Parameters // HttpConnectionParams.setConnectionTimeout(params, 5000); return params; }
From source file:pt.hive.cameo.net.ClientFactory.java
public static DefaultHttpClient getHttpClient(boolean strict) { // creates a new instance of the basic http parameters and then // updates the parameter with a series of pre-defined options that // are defined as the default ones for this factory HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.strict-transfer-encoding", false); params.setBooleanParameter("http.protocol.expect-continue", true); // constructs both the plain and the secure factory objects that are // going to be used in the registration of the plain and secure http // schemes, operation to be performed latter on SocketFactory plainFactory = PlainSocketFactory.getSocketFactory(); SocketFactory secureFactory = strict ? org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory() : SSLSocketFactory.getSocketFactory(); // creates the registry object and registers both the secure and the // insecure http mechanisms for the respective socket factories SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", plainFactory, 80)); registry.register(new Scheme("https", secureFactory, 443)); // creates the manager entity using the creates parameters structure // and the registry for socket factories ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); // creates the default http client using the created thread safe manager // with the provided parameters and registry (as expected) and then // returns the new client to the caller method so that it may be used DefaultHttpClient client = new DefaultHttpClient(manager, params); return client; }
From source file:Main.java
public static DefaultHttpClient setHttpPostProxyParams(Context context, int connTimeout) { Log.d(TAG, "ctx, connTimeout -- called"); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); //schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); /*Log.d(TAG, "----Add Proxy---"); HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(), Constants.PROXY_PORT);//from w w w . j a v a 2 s.co m params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/ /*if ((getWifiName(context).trim()).equalsIgnoreCase("secure-impact")) { Log.d(TAG, "----Add Proxy---"); HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(), Constants.PROXY_PORT); params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }*/ params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(params, connTimeout); HttpConnectionParams.setSoTimeout(params, connTimeout); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params); return mHttpClient; }