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


Java HttpParams類代碼示例

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


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

示例1: get

import org.apache.http.params.HttpParams; //導入依賴的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: getNewHttpClient

import org.apache.http.params.HttpParams; //導入依賴的package包/類
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(); 
   } 
}
 
開發者ID:cheng2016,項目名稱:developNote,代碼行數:24,代碼來源:HttpUtil.java

示例3: a

import org.apache.http.params.HttpParams; //導入依賴的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

示例4: update

import org.apache.http.params.HttpParams; //導入依賴的package包/類
public void update(Socket sock, HttpHost target,
                   boolean secure, HttpParams params)
    throws IOException {

    assertOpen();
    if (target == null) {
        throw new IllegalArgumentException
            ("Target host must not be null.");
    }
    if (params == null) {
        throw new IllegalArgumentException
            ("Parameters must not be null.");
    }

    if (sock != null) {
        this.socket = sock;
        bind(sock, params);
    }
    targetHost = target;
    connSecure = secure;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:DefaultClientConnection.java

示例5: getHttpClientInstance

import org.apache.http.params.HttpParams; //導入依賴的package包/類
public DefaultHttpClient getHttpClientInstance() {
    if (this.httpClient != null) {
        return this.httpClient;
    }
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
    params.setParameter("http.socket.timeout", SOCKET_TIMEOUT);
    params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    params.setParameter("http.useragent", "Apache-HttpClient/Android");
    params.setParameter("http.connection.stalecheck", Boolean.valueOf(false));
    this.httpClient = new DefaultHttpClient(params);
    this.httpClient.addRequestInterceptor(new GzipHttpRequestInterceptor());
    this.httpClient.addResponseInterceptor(new GzipHttpResponseInterceptor());
    this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    return this.httpClient;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:17,代碼來源:RestClient.java

示例6: getHttpClient

import org.apache.http.params.HttpParams; //導入依賴的package包/類
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;
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:24,代碼來源:MyHtttpClient.java

示例7: createSessionInputBuffer

import org.apache.http.params.HttpParams; //導入依賴的package包/類
@Override
protected SessionInputBuffer createSessionInputBuffer(
        final Socket socket,
        int buffersize,
        final HttpParams params) throws IOException {
    if (buffersize == -1) {
        buffersize = 8192;
    }
    SessionInputBuffer inbuffer = super.createSessionInputBuffer(
            socket,
            buffersize,
            params);
    if (wireLog.isDebugEnabled()) {
        inbuffer = new LoggingSessionInputBuffer(
                inbuffer,
                new Wire(wireLog),
                HttpProtocolParams.getHttpElementCharset(params));
    }
    return inbuffer;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:DefaultClientConnection.java

示例8: newInstance

import org.apache.http.params.HttpParams; //導入依賴的package包/類
public CookieSpec newInstance(final HttpParams params) {
    if (params != null) {

        String[] patterns = null;
        Collection<?> param = (Collection<?>) params.getParameter(
                CookieSpecPNames.DATE_PATTERNS);
        if (param != null) {
            patterns = new String[param.size()];
            patterns = param.toArray(patterns);
        }
        boolean singleHeader = params.getBooleanParameter(
                CookieSpecPNames.SINGLE_COOKIE_HEADER, false);

        return new BestMatchSpec(patterns, singleHeader);
    } else {
        return new BestMatchSpec();
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:BestMatchSpecFactory.java

示例9: tunnelProxy

import org.apache.http.params.HttpParams; //導入依賴的package包/類
/**
 * Tracks tunnelling of the connection to a chained proxy.
 * The tunnel has to be established outside by sending a CONNECT
 * request to the previous proxy.
 *
 * @param next      the proxy to which the tunnel was established.
 *  See {@link org.apache.http.conn.ManagedClientConnection#tunnelProxy
 *                                  ManagedClientConnection.tunnelProxy}
 *                  for details.
 * @param secure    <code>true</code> if the tunnel should be
 *                  considered secure, <code>false</code> otherwise
 * @param params    the parameters for tunnelling the connection
 *
 * @throws IOException  in case of a problem
 */
public void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
    throws IOException {

    if (next == null) {
        throw new IllegalArgumentException
            ("Next proxy must not be null.");
    }
    if (params == null) {
        throw new IllegalArgumentException
            ("Parameters must not be null.");
    }

    //@@@ check for proxy in planned route?
    if ((this.tracker == null) || !this.tracker.isConnected()) {
        throw new IllegalStateException("Connection not open.");
    }

    this.connection.update(null, next, secure, params);
    this.tracker.tunnelProxy(next, secure);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:36,代碼來源:AbstractPoolEntry.java

示例10: init

import org.apache.http.params.HttpParams; //導入依賴的package包/類
/**
 * Initializes this connection object with {@link SessionInputBuffer} and
 * {@link SessionOutputBuffer} instances to be used for sending and
 * receiving data. These session buffers can be bound to any arbitrary
 * physical output medium.
 * <p>
 * This method will invoke {@link #createHttpResponseFactory()},
 * {@link #createRequestWriter(SessionOutputBuffer, HttpParams)}
 * and {@link #createResponseParser(SessionInputBuffer, HttpResponseFactory, HttpParams)}
 * methods to initialize HTTP request writer and response parser for this
 * connection.
 *
 * @param inbuffer the session input buffer.
 * @param outbuffer the session output buffer.
 * @param params HTTP parameters.
 */
protected void init(
        final SessionInputBuffer inbuffer,
        final SessionOutputBuffer outbuffer,
        final HttpParams params) {
    if (inbuffer == null) {
        throw new IllegalArgumentException("Input session buffer may not be null");
    }
    if (outbuffer == null) {
        throw new IllegalArgumentException("Output session buffer may not be null");
    }
    this.inbuffer = inbuffer;
    this.outbuffer = outbuffer;
    if (inbuffer instanceof EofSensor) {
        this.eofSensor = (EofSensor) inbuffer;
    }
    this.responseParser = createResponseParser(
            inbuffer,
            createHttpResponseFactory(),
            params);
    this.requestWriter = createRequestWriter(
            outbuffer, params);
    this.metrics = createConnectionMetrics(
            inbuffer.getMetrics(),
            outbuffer.getMetrics());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:42,代碼來源:AbstractHttpClientConnection.java

示例11: DefaultRequestDirector

import org.apache.http.params.HttpParams; //導入依賴的package包/類
@Deprecated
public DefaultRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    this(LogFactory.getLog(DefaultRequestDirector.class),
            requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
            new DefaultRedirectStrategyAdaptor(redirectHandler),
            new AuthenticationStrategyAdaptor(targetAuthHandler),
            new AuthenticationStrategyAdaptor(proxyAuthHandler),
            userTokenHandler,
            params);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:DefaultRequestDirector.java

示例12: setUp

import org.apache.http.params.HttpParams; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    HttpParams httpParams = new BasicHttpParams();
    when(mockHttpClientFactory.create()).thenReturn(mockHttpClient);
    when(mockHttpClient.getParams()).thenReturn(httpParams);
    when(mockHttpClient.getConnectionManager()).thenReturn(mockClientConnectionManager);
    when(mockClientConnectionManager.getSchemeRegistry()).thenReturn(mockSchemeRegistry);
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:11,代碼來源:WebDavStoreTest.java

示例13: setMaxConnections

import org.apache.http.params.HttpParams; //導入依賴的package包/類
/**
 * 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));
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:13,代碼來源:AsyncHttpClient.java

示例14: getNewHttpClient

import org.apache.http.params.HttpParams; //導入依賴的package包/類
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(b.a, sf, WebSocket.DEFAULT_WSS_PORT));
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        return new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:15,代碼來源:MySSLSocketFactory.java

示例15: ak

import org.apache.http.params.HttpParams; //導入依賴的package包/類
private ak(Context context) {
    try {
        dk = context.getApplicationContext();
        this.cv = System.currentTimeMillis() / 1000;
        this.dh = new f();
        if (c.k()) {
            try {
                Logger.getLogger("org.apache.http.wire").setLevel(Level.FINER);
                Logger.getLogger("org.apache.http.headers").setLevel(Level.FINER);
                System.setProperty("org.apache.commons.logging.Log", "org.apache.commons" +
                        ".logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
                System.setProperty("org.apache.commons.logging.simplelog.log.httpclient" +
                        ".wire", BuildConfig.BUILD_TYPE);
                System.setProperty("org.apache.commons.logging.simplelog.log.org.apache" +
                        ".http", BuildConfig.BUILD_TYPE);
                System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http" +
                        ".headers", BuildConfig.BUILD_TYPE);
            } catch (Throwable th) {
            }
        }
        HttpParams basicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 10000);
        this.dg = new DefaultHttpClient(basicHttpParams);
        this.dg.setKeepAliveStrategy(new al(this));
    } catch (Throwable th2) {
        cx.b(th2);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:32,代碼來源:ak.java


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