Code example for BasicHttpParams

Methods: setIntParameter, setParameter

0
 
		if (connectionManager == null) {
			connectionManager = createConnectionManager();
		} 
 
		HttpParams httpParams = new BasicHttpParams();
 
		if (config.getHttpConnectionTimeout() > 0) {
			httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
				config.getHttpConnectionTimeout());
		} 
		if (config.getHttpReadTimeout() > 0) {
			httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getHttpReadTimeout());
		} 
		// 设置cookie策略 
		httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
				 
		// 设置http.protocol.expect-continue参数为false,即不使用Expect:100-Continue握手, 
		// 因为如果服务器不支持HTTP 1.1,则会导致HTTP 417错误。 
		HttpProtocolParams.setUseExpectContinue(httpParams, false);
		// 设置User-Agent 
		HttpProtocolParams.setUserAgent(httpParams, config.getUserAgent());
		// 设置HTTP版本为 HTTP 1.1 
		HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
		 
		 
		DefaultHttpClient httpClient = new LibHttpClient(connectionManager, httpParams);
 
		updateProxySetting(config, httpClient);
 
		if (config.isUseGzip()) {
			httpClient.addRequestInterceptor(new GzipRequestInterceptor());