Exemplo n.º 1
0
  static {
    httpClient = new DefaultHttpClient();
    HttpParams params = httpClient.getParams();

    // set the time out of the connection/ socket. and the cache size
    HttpConnectionParams.setConnectionTimeout(params, 30 * 1000);
    HttpConnectionParams.setSoTimeout(params, 30 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // set the connection manager factory
    params.setParameter(
        ClientPNames.CONNECTION_MANAGER_FACTORY,
        new ClientConnectionManagerFactory() {
          public ClientConnectionManager newInstance(
              HttpParams params, SchemeRegistry schemeRegistry) {
            return new ThreadSafeClientConnManager(params, schemeRegistry);
          }
        });

    // set the redirect, default is true
    HttpClientParams.setRedirecting(params, true);

    // set the client verion
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    // set user-agent
    HttpProtocolParams.setUserAgent(params, "eoeWIKI_Android/0.9");
    // set the charset
    HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    // set not activate Expect:100-Continue
    HttpProtocolParams.setUseExpectContinue(params, false);

    // set the version of the cookie
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2965);
  }
Exemplo n.º 2
0
  private static HttpClient getHttpClient() {

    HttpParams httpParameters = new BasicHttpParams();
    HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8);
    HttpProtocolParams.setHttpElementCharset(httpParameters, HTTP.UTF_8);
    mHttpClient = new DefaultHttpClient(httpParameters);
    mHttpClient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    mHttpClient.getParams().setParameter("http.socket.timeout", new Integer(2000));
    mHttpClient.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8);
    httpParameters.setBooleanParameter("http.protocol.expect-continue", false);

    return mHttpClient;
  }
  /* Create HttpClient Instance with Application Settings Specified */
  private HttpClient getHttpClient(HttpRequestType requestType) {
    HttpParams httpParams = new BasicHttpParams();
    HttpProtocolParams.setContentCharset(httpParams, HTTP.UTF_8);
    HttpProtocolParams.setHttpElementCharset(httpParams, HTTP.UTF_8);

    if (requestType == HttpRequestType.POST) {
      HttpConnectionParams.setConnectionTimeout(httpParams, HTTP_POST_CONNECTION_TIMEOUT);
      HttpConnectionParams.setSoTimeout(httpParams, HTTP_POST_WAITING_FOR_DATA_TIMEOUT);
    } else {
      HttpConnectionParams.setConnectionTimeout(httpParams, HTTP_GET_CONNECTION_TIMEOUT);
      HttpConnectionParams.setSoTimeout(httpParams, HTTP_GET_WAITING_FOR_DATA_TIMEOUT);
    }
    DefaultHttpClient httpclient = new DefaultHttpClient(httpParams);
    httpclient.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8);
    return httpclient;
  }
Exemplo n.º 4
0
 private YammerHttpClient() {
   SchemeRegistry schemeRegistry = new SchemeRegistry();
   schemeRegistry.register(
       new Scheme(HttpHost.DEFAULT_SCHEME_NAME, 80, PlainSocketFactory.getSocketFactory()));
   schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
   DefaultHttpClient defaultHttpClient =
       new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry));
   HttpParams params = defaultHttpClient.getParams();
   HttpConnectionParams.setSoTimeout(params, 5000);
   HttpConnectionParams.setConnectionTimeout(params, 5000);
   HttpConnectionParams.setTcpNoDelay(params, true);
   HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
   HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
   HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
   HttpClientParams.setRedirecting(params, false);
   httpClient = defaultHttpClient;
 }