• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HttpParams类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.http.params.HttpParams的典型用法代码示例。如果您正苦于以下问题:Java HttpParams类的具体用法?Java HttpParams怎么用?Java HttpParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpParams类属于org.apache.http.params包,在下文中一共展示了HttpParams类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: setTimeout

import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
 * Set the connection and socket timeout. By default, 10 seconds.
 *
 * @param timeout the connect/socket timeout in milliseconds, at least 1 second
 */
public void setTimeout(int timeout) {
    if (timeout < 1000) timeout = DEFAULT_SOCKET_TIMEOUT;
    this.timeout = timeout;
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setTimeout(httpParams, this.timeout);
    HttpConnectionParams.setSoTimeout(httpParams, this.timeout);
    HttpConnectionParams.setConnectionTimeout(httpParams, this.timeout);
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:14,代码来源:SyncHttpClient.java


示例17: performRequest

import org.apache.http.params.HttpParams; //导入依赖的package包/类
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
    addHeaders(httpRequest, additionalHeaders);
    addHeaders(httpRequest, request.getHeaders());
    onPrepareRequest(httpRequest);
    HttpParams httpParams = httpRequest.getParams();
    int timeoutMs = request.getTimeoutMs();
    // TODO: Reevaluate this connection timeout based on more wide-scale
    // data collection and possibly different for wifi vs. 3G.
    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
    HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
    return mClient.execute(httpRequest);
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:16,代码来源:HttpClientStack.java


示例18: query

import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
 * Execute Http request and response code
 * @param request - HTTP Request
 * @param expectedCode - expected response code
 * @return - response in JSONObject
 */
public JSON query(HttpRequestBase request, int expectedCode) throws IOException {
    log.info("Requesting: " + request);
    addRequiredHeader(request);

    HttpParams requestParams = request.getParams();
    requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT * 1000);
    requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT * 1000);

    synchronized (httpClient) {
        String response;
        try {
            HttpResponse result = httpClient.execute(request);

            int statusCode = result.getStatusLine().getStatusCode();

            response = getResponseEntity(result);

            if (statusCode != expectedCode) {

                notifier.notifyAbout("Response with code " + statusCode + ": " + extractErrorMessage(response));
                throw new IOException("API responded with wrong status code: " + statusCode);
            } else {
                log.debug("Response: " + response);
            }
        } finally {
            request.abort();
        }

        if (response == null || response.isEmpty()) {
            return JSONNull.getInstance();
        } else {
            return JSONSerializer.toJSON(response, new JsonConfig());
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:42,代码来源:HttpUtils.java


示例19: prepareSocket

import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
 * Performs standard initializations on a newly created socket.
 *
 * @param sock      the socket to prepare
 * @param context   the context for the connection
 * @param params    the parameters from which to prepare the socket
 *
 * @throws IOException      in case of an IO problem
 */
protected void prepareSocket(
        final Socket sock,
        final HttpContext context,
        final HttpParams params) throws IOException {
    sock.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    sock.setSoTimeout(HttpConnectionParams.getSoTimeout(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        sock.setSoLinger(linger > 0, linger);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:DefaultClientConnectionOperator.java


示例20: getIntClientParameter

import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
 * Retrieves the current connection timeout, null if not set or if set to Integer.MIN_VALUE
 * 
 * @return The current timeout
 */
protected Integer getIntClientParameter(final String parameter) {
    HttpParams params = httpClient.getParams();
    int value = params.getIntParameter(parameter, Integer.MIN_VALUE);
    if (value != Integer.MIN_VALUE) {
        return value;
    } else {
        return null;
    }
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:15,代码来源:HCAPAdapter.java



注:本文中的org.apache.http.params.HttpParams类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ServletContextListener类代码示例发布时间:2022-05-20
下一篇:
Java AbstractAction类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap