Java Code Examples for org.apache.http.params.HttpProtocolParams#setContentCharset()
The following examples show how to use
org.apache.http.params.HttpProtocolParams#setContentCharset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpSendClientFactory.java From PoseidonX with Apache License 2.0 | 6 votes |
/** * 创建一个{@link HttpSendClient} 实例 * <p> * 多态 * * @return */ public HttpSendClient newHttpSendClient() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, getConnectionTimeOut()); HttpConnectionParams.setSoTimeout(params, getSoTimeOut()); // HttpConnectionParams.setLinger(params, 1); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); // 解释: 握手的目的,是为了允许客户端在发送请求内容之前,判断源服务器是否愿意接受请求(基于请求头部)。 // Expect:100-Continue握手需谨慎使用,因为遇到不支持HTTP/1.1协议的服务器或者代理时会引起问题。 // 默认开启 // HttpProtocolParams.setUseExpectContinue(params, false); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, getSocketBufferSize()); ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager(); threadSafeClientConnManager.setMaxTotal(getMaxTotalConnections()); threadSafeClientConnManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute()); DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler(getRetryCount(), false); DefaultHttpClient httpClient = new DefaultHttpClient(threadSafeClientConnManager, params); httpClient.setHttpRequestRetryHandler(retryHandler); return new HttpSendClient(httpClient); }
Example 2
Source File: WeixinUtil.java From android-common-utils with Apache License 2.0 | 6 votes |
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(); } }
Example 3
Source File: MainActivity.java From android-advanced-light with MIT License | 6 votes |
/** * 设置默认请求参数,并返回HttpClient * * @return HttpClient */ private HttpClient createHttpClient() { HttpParams mDefaultHttpParams = new BasicHttpParams(); //设置连接超时 HttpConnectionParams.setConnectionTimeout(mDefaultHttpParams, 15000); //设置请求超时 HttpConnectionParams.setSoTimeout(mDefaultHttpParams, 15000); HttpConnectionParams.setTcpNoDelay(mDefaultHttpParams, true); HttpProtocolParams.setVersion(mDefaultHttpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(mDefaultHttpParams, HTTP.UTF_8); //持续握手 HttpProtocolParams.setUseExpectContinue(mDefaultHttpParams, true); HttpClient mHttpClient = new DefaultHttpClient(mDefaultHttpParams); return mHttpClient; }
Example 4
Source File: TestSSLWrong.java From hk with GNU General Public License v3.0 | 6 votes |
public HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(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(); } }
Example 5
Source File: NetworkHelper.java From fanfouapp-opensource with Apache License 2.0 | 6 votes |
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; }
Example 6
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example 7
Source File: MySSLSocketFactory.java From Mobike with Apache License 2.0 | 6 votes |
/** * Gets getUrl DefaultHttpClient which trusts getUrl set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example 8
Source File: M3u8ContentParser.java From NewsMe with Apache License 2.0 | 6 votes |
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); }
Example 9
Source File: MySSLSocketFactory.java From android-project-wo2b with Apache License 2.0 | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example 10
Source File: HttpClientFactory.java From miappstore with Apache License 2.0 | 6 votes |
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; }
Example 11
Source File: NFHttpClient.java From ribbon with Apache License 2.0 | 5 votes |
void init(IClientConfig config, boolean registerMonitor) { HttpParams params = getParams(); HttpProtocolParams.setContentCharset(params, "UTF-8"); params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ThreadSafeClientConnManager.class.getName()); HttpClientParams.setRedirecting(params, config.get(CommonClientConfigKey.FollowRedirects, true)); // set up default headers List<Header> defaultHeaders = new ArrayList<Header>(); defaultHeaders.add(new BasicHeader("Netflix.NFHttpClient.Version", "1.0")); defaultHeaders.add(new BasicHeader("X-netflix-httpclientname", name)); params.setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders); connPoolCleaner = new ConnectionPoolCleaner(name, this.getConnectionManager(), connectionPoolCleanUpScheduler); this.retriesProperty = config.getGlobalProperty(RETRIES.format(name)); this.sleepTimeFactorMsProperty = config.getGlobalProperty(SLEEP_TIME_FACTOR_MS.format(name)); setHttpRequestRetryHandler( new NFHttpMethodRetryHandler(this.name, this.retriesProperty.getOrDefault(), false, this.sleepTimeFactorMsProperty.getOrDefault())); tracer = Monitors.newTimer(EXECUTE_TRACER + "-" + name, TimeUnit.MILLISECONDS); if (registerMonitor) { Monitors.registerObject(name, this); } maxTotalConnectionProperty = config.getDynamicProperty(CommonClientConfigKey.MaxTotalHttpConnections); maxTotalConnectionProperty.onChange(newValue -> ((ThreadSafeClientConnManager) getConnectionManager()).setMaxTotal(newValue) ); maxConnectionPerHostProperty = config.getDynamicProperty(CommonClientConfigKey.MaxHttpConnectionsPerHost); maxConnectionPerHostProperty.onChange(newValue -> ((ThreadSafeClientConnManager) getConnectionManager()).setDefaultMaxPerRoute(newValue) ); connIdleEvictTimeMilliSeconds = config.getGlobalProperty(CONN_IDLE_EVICT_TIME_MILLIS.format(name)); }
Example 12
Source File: ApiRequest.java From Kingdee-K3Cloud-Web-Api with GNU General Public License v3.0 | 5 votes |
private HttpClient getHttpClient() { if (this._httpClient == null) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpConnectionParams.setConnectionTimeout(params, 300000); HttpConnectionParams.setSoTimeout(params, 300000); 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); this._httpClient = new DefaultHttpClient(conMgr, params); if (this._cookieStore != null) { DefaultHttpClient dhttpclient = (DefaultHttpClient) this._httpClient; dhttpclient.setCookieStore(this._cookieStore); } } return this._httpClient; }
Example 13
Source File: OneKeyWifi.java From zhangshangwuda with Apache License 2.0 | 5 votes |
public 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); HttpConnectionParams.setConnectionTimeout(params, 5 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); 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(); } }
Example 14
Source File: WifiFragmentSupport.java From zhangshangwuda with Apache License 2.0 | 5 votes |
public 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); HttpConnectionParams.setConnectionTimeout(params, 5 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); 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(); } }
Example 15
Source File: HttpUtils.java From LitePlayer with Apache License 2.0 | 5 votes |
public static HttpParams getParams() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 4000); HttpConnectionParams.setSoTimeout(params, 10000); ConnManagerParams.setTimeout(params, 4000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Windows NT 6.1; WOW64)" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36"); return params; }
Example 16
Source File: Download.java From LitePlayer with Apache License 2.0 | 5 votes |
/** * 设置http参数 不能设置soTimeout * @return HttpParams http参数 */ private static HttpParams getHttpParams() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params, true); HttpProtocolParams.setUserAgent(params, UA); // ConnManagerParams.setTimeout(params, 10000); // HttpConnectionParams.setConnectionTimeout(params, 10000); return params; }
Example 17
Source File: StreamClientImpl.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; HttpProtocolParams.setContentCharset(globalParams, getConfiguration().getContentCharset()); HttpProtocolParams.setUseExpectContinue(globalParams, false); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking HttpConnectionParams.setConnectionTimeout(globalParams, (getConfiguration().getTimeoutSeconds()+5) * 1000); HttpConnectionParams.setSoTimeout(globalParams, (getConfiguration().getTimeoutSeconds()+5) * 1000); HttpConnectionParams.setStaleCheckingEnabled(globalParams, getConfiguration().getStaleCheckingEnabled()); if (getConfiguration().getSocketBufferSize() != -1) HttpConnectionParams.setSocketBufferSize(globalParams, getConfiguration().getSocketBufferSize()); // Only register 80, not 443 and SSL SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); clientConnectionManager = new PoolingClientConnectionManager(registry); clientConnectionManager.setMaxTotal(getConfiguration().getMaxTotalConnections()); clientConnectionManager.setDefaultMaxPerRoute(getConfiguration().getMaxTotalPerRoute()); httpClient = new DefaultHttpClient(clientConnectionManager, globalParams); if (getConfiguration().getRequestRetryCount() != -1) { httpClient.setHttpRequestRetryHandler( new DefaultHttpRequestRetryHandler(getConfiguration().getRequestRetryCount(), false) ); } }
Example 18
Source File: HttpsUtils.java From RipplePower with Apache License 2.0 | 5 votes |
public 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); HttpProtocolParams.setUserAgent(params, HttpHeader.getUA()); 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); DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params); httpClient.setCookieStore(new BasicCookieStore()); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 25000); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 25000); return httpClient; } catch (Exception e) { return new DefaultHttpClient(); } }
Example 19
Source File: HttpTaskFactory.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected HttpParams basicParams() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); // Make sure this connection will timeout HttpConnectionParams.setConnectionTimeout(params, 300000); HttpConnectionParams.setSoTimeout(params, 300000); return params; }
Example 20
Source File: EasyHttpClient.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
/** * Function that creates a ClientConnectionManager which can handle http and https. * In case of https self signed or invalid certificates will be accepted. */ @Override protected ClientConnectionManager createClientConnectionManager() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), HTTP_PORT)); registry.register(new Scheme("https", new EasySSLSocketFactory(), HTTPS_PORT)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); return manager; }