Java 类org.apache.http.params.HttpConnectionParams 实例源码

项目:letv    文件:PoolingClientConnectionManager.java   
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);
}
项目:boohee_v5.6    文件:b.java   
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);
}
项目:GitHub    文件:HttpClientStack.java   
/**
 * 请求执行
 * @param request the request to perform
 * @param additionalHeaders additional headers to be sent together with
 *         {@link Request#getHeaders()}
 * @return
 * @throws IOException
 * @throws AuthFailureError
 */
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    //传入request 进行创建封装过后的httprequest子类 httpurlrequest
    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);
}
项目:DaiGo    文件:LocationService.java   
@Override
public void run() {
    try {
        BasicHttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 500);
        HttpConnectionParams.setSoTimeout(httpParams, 500);

        HttpClient httpclient = new DefaultHttpClient(httpParams);

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("latitude", "" + latitude));
        params.add(new BasicNameValuePair("longitude", "" + longitude));
        params.add(new BasicNameValuePair("userid", userId));

        //服务器地址,指向Servlet
        HttpPost httpPost = new HttpPost(ServerUtil.SLUpdateLocation);

        final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "utf-8");//以UTF-8格式发送
        httpPost.setEntity(entity);
        //对提交数据进行编码
        httpclient.execute(httpPost);
    } catch (Exception e) {

    }
}
项目:android-advanced-light    文件:MainActivity.java   
/**
 * 设置默认请求参数,并返回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;

}
项目:letv    文件:HttpEngine.java   
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;
}
项目:Huochexing12306    文件:MyHtttpClient.java   
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;
}
项目:lams    文件:DefaultHttpClientConnection.java   
@Override
public void bind(
        final Socket socket,
        final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    assertNotOpen();
    socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
    socket.setKeepAlive(HttpConnectionParams.getSoKeepalive(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    super.bind(socket, params);
}
项目:lams    文件:DefaultHttpServerConnection.java   
@Override
public void bind(final Socket socket, final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    assertNotOpen();
    socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
    socket.setKeepAlive(HttpConnectionParams.getSoKeepalive(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    super.bind(socket, params);
}
项目:lams    文件:SocketHttpClientConnection.java   
/**
 * Binds this connection to the given {@link Socket}. This socket will be
 * used by the connection to send and receive data.
 * <p>
 * This method will invoke {@link #createSessionInputBuffer(Socket, int, HttpParams)}
 * and {@link #createSessionOutputBuffer(Socket, int, HttpParams)} methods
 * to create session input / output buffers bound to this socket and then
 * will invoke {@link #init(SessionInputBuffer, SessionOutputBuffer, HttpParams)}
 * method to pass references to those buffers to the underlying HTTP message
 * parser and formatter.
 * <p>
 * After this method's execution the connection status will be reported
 * as open and the {@link #isOpen()} will return <code>true</code>.
 *
 * @param socket the socket.
 * @param params HTTP parameters.
 * @throws IOException in case of an I/O error.
 */
protected void bind(
        final Socket socket,
        final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.socket = socket;

    int buffersize = HttpConnectionParams.getSocketBufferSize(params);

    init(
            createSessionInputBuffer(socket, buffersize, params),
            createSessionOutputBuffer(socket, buffersize, params),
            params);

    this.open = true;
}
项目:lams    文件:SocketHttpServerConnection.java   
/**
 * Binds this connection to the given {@link Socket}. This socket will be
 * used by the connection to send and receive data.
 * <p>
 * This method will invoke {@link #createSessionInputBuffer(Socket, int, HttpParams)}
 * and {@link #createSessionOutputBuffer(Socket, int, HttpParams)} methods
 * to create session input / output buffers bound to this socket and then
 * will invoke {@link #init(SessionInputBuffer, SessionOutputBuffer, HttpParams)}
 * method to pass references to those buffers to the underlying HTTP message
 * parser and formatter.
 * <p>
 * After this method's execution the connection status will be reported
 * as open and the {@link #isOpen()} will return <code>true</code>.
 *
 * @param socket the socket.
 * @param params HTTP parameters.
 * @throws IOException in case of an I/O error.
 */
protected void bind(final Socket socket, final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.socket = socket;

    int buffersize = HttpConnectionParams.getSocketBufferSize(params);

    init(
            createSessionInputBuffer(socket, buffersize, params),
            createSessionOutputBuffer(socket, buffersize, params),
            params);

    this.open = true;
}
项目:boohee_v5.6    文件:d.java   
private d() {
    try {
        HandlerThread handlerThread = new HandlerThread("StatDispatcher");
        handlerThread.start();
        d = handlerThread.getId();
        this.b = new Handler(handlerThread.getLooper());
        HttpParams basicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 10000);
        this.a = new DefaultHttpClient(basicHttpParams);
        this.a.setKeepAliveStrategy(new e(this));
        if (StatConfig.b() != null) {
            this.a.getParams().setParameter("http.route.default-proxy", StatConfig.b());
        }
    } catch (Object th) {
        c.e(th);
    }
}
项目:appinventor-extensions    文件:WebServiceUtil.java   
/**
 * Returns the one <code>WebServiceUtil</code> instance
 * @return the one <code>WebServiceUtil</code> instance
 */
public static WebServiceUtil getInstance() {
  // This needs to be here instead of in the constructor because
  // it uses classes that are in the AndroidSDK and thus would
  // cause Stub! errors when running the component descriptor.
  synchronized(httpClientSynchronizer) {
    if (httpClient == null) {
      SchemeRegistry schemeRegistry = new SchemeRegistry();
      schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
      schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
      BasicHttpParams params = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
      HttpConnectionParams.setSoTimeout(params, 20 * 1000);
      ConnManagerParams.setMaxTotalConnections(params, 20);
      ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params,
          schemeRegistry);
      WebServiceUtil.httpClient = new DefaultHttpClient(manager, params);
    }
  }
  return INSTANCE;
}
项目:JSSample    文件:HttpUtils.java   
public static SchemeRegistry getSchemeRegistry() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
        SSLSocketFactory sf = new SSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);
        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));
        return registry;
    } catch (Exception e) {
        return null;
    }
}
项目:MyAndroidDemo    文件:CustomerHttpClient.java   
/**
 * 从可用的HttpClient池中返回一个默认10秒的HttpClient对象,该方法是同步的。
 * 
 * @return 可用的.HttpClient对象
 */
public static synchronized HttpClient getHttpClient() {
    if (null == customerHttpClient) {
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, CHARSET);
        HttpProtocolParams.setUseExpectContinue(params, true);
        HttpProtocolParams.setUserAgent(params,
                        "Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "
                                + "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
        ConnManagerParams.setTimeout(params, 10000);

        HttpConnectionParams.setConnectionTimeout(params, 10000);

        HttpConnectionParams.setSoTimeout(params, 10000);

        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);
        customerHttpClient = new DefaultHttpClient(conMgr, params);
    }
    return customerHttpClient;
}
项目:NewsMe    文件:M3u8ContentParser.java   
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);
}
项目:CuiMarket    文件:HttpClientFactory.java   
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;
}
项目:darksms    文件:HttpUtils.java   
private static AndroidHttpClient createHttpClient(Context context) {
    String userAgent = MmsConfig.getUserAgent();
    AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, context);
    HttpParams params = client.getParams();
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    // set the socket timeout
    int soTimeout = MmsConfig.getHttpSocketTimeout();

    if (DEBUG) {
        Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, "
                + ", UA=" + userAgent);
    }
    HttpConnectionParams.setSoTimeout(params, soTimeout);
    return client;
}
项目:SinaVideoSdkDemo    文件:M3u8ContentParser.java   
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);
}
项目:cpe-manifest-android-experience    文件:EasySSLSocketFactory.java   
/**
 * @see SocketFactory#connectSocket(Socket, String, int,
 *      InetAddress, int, HttpParams)
 */
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            localPort = 0; // indicates "any"
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;

}
项目:PanoramaGL    文件:EasySSLSocketFactory.java   
/**
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
 *      java.lang.String, int, java.net.InetAddress, int,
 *      org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock, String host, int port,
                InetAddress localAddress, int localPort, HttpParams params)
                throws IOException, UnknownHostException, ConnectTimeoutException {
        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);

        InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
        SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

        if ((localAddress != null) || (localPort > 0)) {
                // we need to bind explicitly
                if (localPort < 0) {
                        localPort = 0; // indicates "any"
                }
                InetSocketAddress isa = new InetSocketAddress(localAddress,
                                localPort);
                sslsock.bind(isa);
        }

        sslsock.connect(remoteAddress, connTimeout);
        sslsock.setSoTimeout(soTimeout);
        return sslsock;

}
项目:SaveVolley    文件:HttpClientStack.java   
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    // 创建一个 Apache HTTP 请求
    HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
    // 添加 performRequest 方法传入的 头信息
    addHeaders(httpRequest, additionalHeaders);
    // 添加 Volley 抽象请求了 Request 设置的 头信息
    addHeaders(httpRequest, request.getHeaders());
    // 回调( 如果被覆写的话 ) 预请求 方法
    onPrepareRequest(httpRequest);
    // 获取 Apache 请求的 HttpParams 对象
    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);
    // 设置 SO_TIMEOUT
    HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
    // 开始执行请求
    return mClient.execute(httpRequest);
}
项目:NetEasyNews    文件:HttpClientFactory.java   
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;
}
项目:lr_dialer    文件:AbstractAjaxCallback.java   
private static DefaultHttpClient getClient()
{
    if (client == null || !REUSE_CLIENT)
    {
        AQUtility.debug("creating http client");
        HttpParams httpParams = new BasicHttpParams();
        //httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpConnectionParams.setConnectionTimeout(httpParams, NET_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, NET_TIMEOUT);
        //ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(NETWORK_POOL));
        ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25));
        //Added this line to avoid issue at: http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt
        HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, registry);
        client = new DefaultHttpClient(cm, httpParams);
    }
    return client;
}
项目:subsonic    文件:ProxyController.java   
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = ServletRequestUtils.getRequiredStringParameter(request, "url");

    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
    HttpGet method = new HttpGet(url);

    InputStream in = null;
    try {
        HttpResponse resp = client.execute(method);
        int statusCode = resp.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            response.sendError(statusCode);
        } else {
            in = resp.getEntity().getContent();
            IOUtils.copy(in, response.getOutputStream());
        }
    } finally {
        IOUtils.closeQuietly(in);
        client.getConnectionManager().shutdown();
    }
    return null;
}
项目:TvLauncher    文件:HttpRequest.java   
/**
 * 发送一个GET请求
 *
 * @return
 * @throws Exception
 */
private HttpRequest get() throws Exception {
    HttpGet httpget = null;
    String result = null;
    int respCode = -1;
    try {
        httpget = new HttpGet(reqUrl);
        httpget.setHeader("Connection", "close");
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 1000 * 60);
        httpget.setParams(params);
        HttpResponse response = new DefaultHttpClient().execute(httpget);
        result = EntityUtils.toString(response.getEntity(), charset).trim();
        respCode = response.getStatusLine().getStatusCode();
        if (respCode == HttpStatus.SC_OK) {
            this.respResult = result;
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (null != httpget) {
            httpget = null;
        }
    }
    return this;
}
项目:GitHub    文件:HttpClientStack.java   
@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);
}
项目:publicProject    文件:HttpClientStack.java   
@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);
}
项目:airgram    文件:HttpClientStack.java   
@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);
}
项目:Hotspot-master-devp    文件:HttpUtils.java   
public HttpUtils configTimeout(int timeout) {
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setTimeout(httpParams, timeout);
    HttpConnectionParams.setSoTimeout(httpParams, timeout);
    HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
    return this;
}
项目:Codeforces    文件:HttpClientStack.java   
@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);
}
项目:papara-android    文件:PaparaHttpClientStack.java   
@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);
}
项目:letv    文件:ImmersionHttpClient.java   
private HttpResponse b0449щ0449щщ0449(HttpUriRequest httpUriRequest, Map map, int i) throws Exception {
    URI uri = httpUriRequest.getURI();
    String trim = uri.getHost() != null ? uri.getHost().trim() : "";
    if (trim.length() > 0) {
        httpUriRequest.setHeader("Host", trim);
    }
    if (map != null) {
        for (Object next : map.entrySet()) {
            if (((b04170417041704170417З + b0417ЗЗЗЗ0417) * b04170417041704170417З) % bЗ0417ЗЗЗ0417 != bЗЗЗЗЗ0417) {
                b04170417041704170417З = 81;
                bЗЗЗЗЗ0417 = 31;
            }
            Entry entry = (Entry) next;
            httpUriRequest.setHeader((String) entry.getKey(), (String) entry.getValue());
        }
    }
    Header[] allHeaders = httpUriRequest.getAllHeaders();
    Log.d(b043D043Dнн043Dн, "request URI [" + httpUriRequest.getURI() + "]");
    for (Object obj : allHeaders) {
        Log.d(b043D043Dнн043Dн, "request header [" + obj.toString() + "]");
    }
    HttpConnectionParams.setSoTimeout(this.bнн043Dн043Dн.getParams(), i);
    HttpResponse execute = this.bнн043Dн043Dн.execute(httpUriRequest);
    if (execute != null) {
        return execute;
    }
    throw new RuntimeException("Null response returned.");
}
项目:GeekZone    文件:HttpClientStack.java   
@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);
}
项目:lams    文件:HttpClientParams.java   
/**
 * Get the connectiion manager timeout value.
 * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}.
 * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT}
 * which defaults to 0 if not defined.
 *
 * @since 4.2
 * @return the timeout value
 */
public static long getConnectionManagerTimeout(final HttpParams params) {
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT);
    if (timeout != null) {
        return timeout.longValue();
    }
    return HttpConnectionParams.getConnectionTimeout(params);
}
项目:lams    文件:DefaultRequestDirector.java   
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    HttpRoute route = req.getRoute();
    HttpRequest wrapper = req.getRequest();

    int connectCount = 0;
    for (;;) {
        context.setAttribute(ExecutionContext.HTTP_REQUEST, wrapper);
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (IOException ex) {
            try {
                managedConn.close();
            } catch (IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (this.log.isInfoEnabled()) {
                    this.log.info("I/O exception ("+ ex.getClass().getName() +
                            ") caught when connecting to the target host: "
                            + ex.getMessage());
                    if (this.log.isDebugEnabled()) {
                        this.log.debug(ex.getMessage(), ex);
                    }
                    this.log.info("Retrying connect");
                }
            } else {
                throw ex;
            }
        }
    }
}
项目:lams    文件:DefaultHttpClient.java   
/**
 * Saves the default set of HttpParams in the provided parameter.
 * These are:
 * <ul>
 * <li>{@link CoreProtocolPNames#PROTOCOL_VERSION}: 1.1</li>
 * <li>{@link CoreProtocolPNames#HTTP_CONTENT_CHARSET}: ISO-8859-1</li>
 * <li>{@link CoreConnectionPNames#TCP_NODELAY}: true</li>
 * <li>{@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}: 8192</li>
 * <li>{@link CoreProtocolPNames#USER_AGENT}: Apache-HttpClient/<release> (java 1.5)</li>
 * </ul>
 */
public static void setDefaultHttpParams(HttpParams params) {
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo
        ("org.apache.http.client", DefaultHttpClient.class.getClassLoader());
    final String release = (vi != null) ?
        vi.getRelease() : VersionInfo.UNAVAILABLE;
    HttpProtocolParams.setUserAgent(params,
            "Apache-HttpClient/" + release + " (java 1.5)");
}
项目:lams    文件:DefaultClientConnectionOperator.java   
/**
 * 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);
    }
}
项目:lams    文件:PlainSocketFactory.java   
/**
 * @since 4.1
 */
public Socket connectSocket(
        final Socket socket,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpParams params) throws IOException, ConnectTimeoutException {
    if (remoteAddress == null) {
        throw new IllegalArgumentException("Remote address may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    Socket sock = socket;
    if (sock == null) {
        sock = createSocket();
    }
    if (localAddress != null) {
        sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
        sock.bind(localAddress);
    }
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    try {
        sock.setSoTimeout(soTimeout);
        sock.connect(remoteAddress, connTimeout);
    } catch (SocketTimeoutException ex) {
        throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
    }
    return sock;
}
项目:iosched-reader    文件:HttpClientStack.java   
@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);
}