當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientParams類代碼示例

本文整理匯總了Java中org.apache.http.client.params.HttpClientParams的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientParams類的具體用法?Java HttpClientParams怎麽用?Java HttpClientParams使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpClientParams類屬於org.apache.http.client.params包,在下文中一共展示了HttpClientParams類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import org.apache.http.client.params.HttpClientParams; //導入依賴的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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:PoolingClientConnectionManager.java

示例2: a

import org.apache.http.client.params.HttpClientParams; //導入依賴的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);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:b.java

示例3: createHttpParams

import org.apache.http.client.params.HttpClientParams; //導入依賴的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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:HttpEngine.java

示例4: createHttpParams

import org.apache.http.client.params.HttpClientParams; //導入依賴的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;
}
 
開發者ID:cuilitang,項目名稱:CuiMarket,代碼行數:20,代碼來源:HttpClientFactory.java

示例5: createHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
/**
 * Create a thread-safe client. This client does not do redirecting, to allow us to capture
 * correct "error" codes.
 *
 * @return HttpClient
 */
public static final DefaultHttpClient createHttpClient() {
    // Sets up the http part of the service.
    final SchemeRegistry supportedSchemes = new SchemeRegistry();

    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    final SocketFactory sf = PlainSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("http", sf, 80));
    supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    
    // Set some client http client parameter defaults.
    final HttpParams httpParams = createHttpParams();
    HttpClientParams.setRedirecting(httpParams, false);

    final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
            supportedSchemes);
    return new DefaultHttpClient(ccm, httpParams);
}
 
開發者ID:Kamshak,項目名稱:foursquared,代碼行數:25,代碼來源:AbstractHttpApi.java

示例6: doGet

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
/**
 * Do a http get for the given url.
 *
 * @param url requested url
 * @param parameters request parameters
 * @param accessor oauth accessor
 * @return the http response
 * @throws IOException
 * @throws {@link YNoteException}
 */
public static HttpResponse doGet(String url, Map<String, String> parameters,
        OAuthAccessor accessor) throws IOException, YNoteException {
    // add ynote parameters to the url
    OAuth.addParameters(url, parameters == null ? null : parameters.entrySet());
    HttpGet get = new HttpGet(url);
    // sign all parameters, including oauth parameters and ynote parameters
    // and add the oauth related information into the header        
    Header oauthHeader = getAuthorizationHeader(url, OAuthMessage.GET,
            parameters, accessor);
    get.addHeader(oauthHeader);
    HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, false);
    get.setParams(params);
    HttpResponse response = client.execute(get);
    if ((response.getStatusLine().getStatusCode() / 100) != 2) {
        YNoteException e = wrapYNoteException(response);
        throw e;
    }
    return response;
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:31,代碼來源:YNoteHttpUtils.java

示例7: createHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
/**
 * Create a thread-safe client. This client does not do redirecting, to allow us to capture
 * correct "error" codes.
 *
 * @return HttpClient
 */
public static final DefaultHttpClient createHttpClient() {
    // Sets up the http part of the service.
    final SchemeRegistry supportedSchemes = new SchemeRegistry();

    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    final SocketFactory sf = PlainSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("http", sf, 80));

    // Set some client http client parameter defaults.
    final HttpParams httpParams = createHttpParams();
    HttpClientParams.setRedirecting(httpParams, false);

    final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
            supportedSchemes);
    return new DefaultHttpClient(ccm, httpParams);
}
 
開發者ID:vsvankhede,項目名稱:foursquared.eclair,代碼行數:24,代碼來源:AbstractHttpApi.java

示例8: newInstance

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
public static AndroidHttpClient newInstance(String paramString, Context paramContext)
{
  BasicHttpParams localBasicHttpParams = new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(localBasicHttpParams, false);
  HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 20000);
  HttpConnectionParams.setSoTimeout(localBasicHttpParams, 20000);
  HttpConnectionParams.setSocketBufferSize(localBasicHttpParams, 8192);
  HttpClientParams.setRedirecting(localBasicHttpParams, false);
  if (paramContext == null) {}
  for (SSLSessionCache localSSLSessionCache = null;; localSSLSessionCache = new SSLSessionCache(paramContext))
  {
    HttpProtocolParams.setUserAgent(localBasicHttpParams, paramString);
    SchemeRegistry localSchemeRegistry = new SchemeRegistry();
    localSchemeRegistry.register(new Scheme("http", ElegantPlainSocketFactory.getSocketFactory(), 80));
    localSchemeRegistry.register(new Scheme("https", getSocketFactory(localSSLSessionCache), 443));
    ConnManagerParamBean localConnManagerParamBean = new ConnManagerParamBean(localBasicHttpParams);
    localConnManagerParamBean.setConnectionsPerRoute(new ConnPerRouteBean(4));
    localConnManagerParamBean.setMaxTotalConnections(8);
    return new AndroidHttpClient(new ElegantThreadSafeConnManager(localBasicHttpParams, localSchemeRegistry), localBasicHttpParams);
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:22,代碼來源:AndroidHttpClient.java

示例9: getHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
public HttpClient getHttpClient() {  
    // 創建 HttpParams 以用來設置 HTTP 參數(這一部分不是必需的)  
    this.httpParams = new BasicHttpParams();  
    // 設置連接超時和 Socket 超時,以及 Socket 緩存大小  
    HttpConnectionParams.setConnectionTimeout(httpParams, 20 * 1000);  
    HttpConnectionParams.setSoTimeout(httpParams, 20 * 1000);  
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);  
    // 設置重定向,缺省為 true  
    HttpClientParams.setRedirecting(httpParams, true);  
    // 設置 user agent  
    String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";  
    HttpProtocolParams.setUserAgent(httpParams, userAgent);  
    // 創建一個 HttpClient 實例  
    // 注意 HttpClient httpClient = new HttpClient(); 是Commons HttpClient  
    // 中的用法,在 Android 1.5 中我們需要使用 Apache 的缺省實現 DefaultHttpClient  
    httpClient = new DefaultHttpClient(httpParams);  
    return httpClient;  
}
 
開發者ID:reallin,項目名稱:CrashHandler,代碼行數:19,代碼來源:CrashHandler.java

示例10: CookieRestTemplate

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
public CookieRestTemplate() {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, false);

    //REGISTERS SCHEMES FOR BOTH HTTP AND HTTPS
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    registry.register(new Scheme("https", sslSocketFactory, 443));

    ClientConnectionManager conman = new ThreadSafeClientConnManager(params, registry);
    httpClient = new DefaultHttpClient(conman, params);
    HttpComponentsClientHttpRequestFactory hcchrf = new StatefulHttpComponentsClientHttpRequestFactory(httpClient, httpContext);
    hcchrf.setConnectTimeout(30 * 1000);
    setRequestFactory(hcchrf);
}
 
開發者ID:murielK,項目名稱:AndroidWPTemplate,代碼行數:22,代碼來源:CookieRestTemplate.java

示例11: getHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
public HttpClient getHttpClient() {
	// 鍒涘緩 HttpParams 浠ョ敤鏉ヨ緗� HTTP 鍙傛暟锛堣繖涓�閮ㄥ垎涓嶆槸蹇呴渶鐨勶級
	HttpParams httpParams = new BasicHttpParams();
	// 璁劇疆榪炴帴瓚呮椂鍜� Socket 瓚呮椂锛屼互鍙� Socket 緙撳瓨澶у皬
	HttpConnectionParams.setConnectionTimeout(httpParams, 30 * 1000);
	HttpConnectionParams.setSoTimeout(httpParams, 60 * 1000);
	HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
	// 璁劇疆閲嶅畾鍚戯紝緙虹渷涓� true
	HttpClientParams.setRedirecting(httpParams, true);
	// 璁劇疆 user agent
	String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
	HttpProtocolParams.setUserAgent(httpParams, userAgent);
	// 鍒涘緩涓�涓� HttpClient 瀹炰緥
	// 娉ㄦ剰 HttpClient httpClient = new HttpClient(); 鏄疌ommons HttpClient
	// 涓殑鐢ㄦ硶锛屽湪 Android 1.5 涓垜浠渶瑕佷嬌鐢� Apache 鐨勭己鐪佸疄鐜� DefaultHttpClient
	httpClient = new DefaultHttpClient(httpParams);
	return httpClient;
}
 
開發者ID:AfirSraftGarrier,項目名稱:ACCAndroid,代碼行數:19,代碼來源:BaseHttpOperator.java

示例12: createDefaultHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
public static DefaultHttpClient createDefaultHttpClient(boolean threadSafe,
		boolean enableRedirect) {
	HttpParams httpParams = new BasicHttpParams();
	HttpClientParams.setRedirecting(httpParams, enableRedirect);
	setTimeout(httpParams, Constants.HTTP_REQUEST_TIME_OUT * 1000);

	if (threadSafe) {
		SchemeRegistry supportedSchemes = new SchemeRegistry();
		SocketFactory sf = PlainSocketFactory.getSocketFactory();
		supportedSchemes.register(new Scheme("http", sf, 80));
		ClientConnectionManager ccm = new ThreadSafeClientConnManager(
				httpParams, supportedSchemes);
		return new DefaultHttpClient(ccm, httpParams);
	} else {
		return new DefaultHttpClient(httpParams);
	}
}
 
開發者ID:coodoing,項目名稱:dataasync,代碼行數:18,代碼來源:HttpHandler.java

示例13: getHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
private HttpClient getHttpClient() {
	synchronized (mClientLock) {
		if ((null == mHttpClient) || mConnectionConfig.isFullAsync()) {			
			HttpParams httpParameters = new BasicHttpParams();
			HttpConnectionParams.setConnectionTimeout(httpParameters, mConnectionConfig.getConnectionTimeout());
			HttpConnectionParams.setSoTimeout(httpParameters, mConnectionConfig.getReadTimeout());
			HttpClientParams.setRedirecting(httpParameters, false);

               if (mConnectionConfig.getSchemeRegistry() != null) {
                   ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(httpParameters, mConnectionConfig.getSchemeRegistry());
                   mHttpClient = new DefaultHttpClient(connectionManager, httpParameters);
               } else {
                   mHttpClient = new DefaultHttpClient(httpParameters);
               }
		}
		
		return mHttpClient;
	}
}
 
開發者ID:open-rnd,項目名稱:android-connection-handler,代碼行數:20,代碼來源:ConnectionHandler.java

示例14: initHttpParams

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
private BasicHttpParams initHttpParams() {
    BasicHttpParams params = new BasicHttpParams();
    if (socketTimeout > -1) {
        HttpConnectionParams.setSoTimeout(params, (int) socketTimeoutUnits.toMillis(socketTimeout));
    }

    if (establishConnectionTimeout > -1) {
        HttpConnectionParams.setConnectionTimeout(params,
            (int)establishConnectionTimeoutUnits.toMillis(establishConnectionTimeout)
        );
    }

    if (connectionCheckoutTimeoutMs > -1) {
        HttpClientParams.setConnectionManagerTimeout(params, connectionCheckoutTimeoutMs);
    }

    return params;
}
 
開發者ID:CenturyLinkCloud,項目名稱:clc-java-sdk,代碼行數:19,代碼來源:SdkClientBuilder.java

示例15: getHttpClient

import org.apache.http.client.params.HttpClientParams; //導入依賴的package包/類
/**
 * Returns the HttpClient singleton.
 */
public static synchronized HttpClient getHttpClient() {
    if (httpClient == null) {
        if (AppConfig.DEBUG) Log.d(TAG, "Creating new instance of HTTP client");

        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreProtocolPNames.USER_AGENT, AppPreferences.USER_AGENT);
        params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS);
        params.setBooleanParameter("http.protocol.reject-relative-redirect",
                false);
        HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
        HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
        HttpClientParams.setRedirecting(params, true);

        httpClient = new DefaultHttpClient(createClientConnectionManager(), params);
        // Workaround for broken URLs in redirection
        ((AbstractHttpClient) httpClient)
                .setRedirectHandler(new APRedirectHandler());
    }
    return httpClient;
}
 
開發者ID:danieloeh,項目名稱:AntennaPodSP,代碼行數:24,代碼來源:AntennapodHttpClient.java


注:本文中的org.apache.http.client.params.HttpClientParams類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。