Android Http Get getHttpClient()

Here you can find the source of getHttpClient()

Description

Get singleton of HttpClient object.

Return

an HttpClient object with connection parameters set

Declaration

private static HttpClient getHttpClient() 

Method Source Code

//package com.java2s;

import org.apache.http.client.HttpClient;

import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

public class Main {
    /** The time it takes for our client to timeout */
    public static final int HTTP_TIMEOUT = 10 * 1000;
    /** Single instance of our HttpClient */
    private static HttpClient httpClient;

    /**// w  ww.j a  v  a  2  s  .  co  m
     * Get singleton of HttpClient object.
     *
     * @return an HttpClient object with connection parameters set
     */
    private static HttpClient getHttpClient() {
        if (httpClient == null) {
            httpClient = new DefaultHttpClient();
            final HttpParams params = httpClient.getParams();
            HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
            HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
            ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
        }
        return httpClient;
    }
}

Related

  1. handleXMLResponse(HttpResponse response)
  2. getStringFromConnection( HttpURLConnection connection)
  3. httpGetRequestParseParams( String paramString)
  4. formatHttpHeaders(Map headers)
  5. getStringResponseData(HttpResponse httpResponse)
  6. maybeCreateHttpClient()
  7. sendGetRequest(String path)
  8. fetchData(String url)