Code example for HttpParams

Methods: setIntParameter, setLongParameter, setParameter

0
 * The AsyncHttpClient can be used to make asynchronous GET, POST, PUT and  
 * DELETE HTTP requests in your Android applications. Requests can be made 
 * with additional parameters by passing a {@link RequestParams} instance, 
 * and responses can be handled by passing an anonymously overridden  
 * {@link AsyncHttpResponseHandler} instance. 
 * <p> 
 * For example: 
 * <p> 
 * <pre> 
 * AsyncHttpClient client = new AsyncHttpClient(); 
 * client.get("http://www.google.com", new AsyncHttpResponseHandler() { 
 *     &#064;Override 
 *     public void onSuccess(String response) { 
 *         System.out.println(response); 
 *     } 
 * }); 
 * </pre> 
 */ 
public class AsyncHttpClient { 
    private static final String VERSION = "1.4.3";
 
    private static final int DEFAULT_MAX_CONNECTIONS = 10;
    private static final int DEFAULT_SOCKET_TIMEOUT = 10 * 1000;
    private static final int DEFAULT_MAX_RETRIES = 5;
    private static final int DEFAULT_SOCKET_BUFFER_SIZE = 8192;
    private static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
    private static final String ENCODING_GZIP = "gzip";
 
    private static int maxConnections = DEFAULT_MAX_CONNECTIONS;
    private static int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
 
    private final DefaultHttpClient httpClient;
    private final HttpContext httpContext;
    private ThreadPoolExecutor threadPool;
    private final Map<Context, List<WeakReference<Future<?>>>> requestMap;
    private final Map<String, String> clientHeaderMap;
 
 
    /** 
     * Creates a new AsyncHttpClient. 
     */ 
    public AsyncHttpClient() { 
        BasicHttpParams httpParams = new BasicHttpParams();
 
        ConnManagerParams.setTimeout(httpParams, socketTimeout);
        ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections));
        ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
 
        HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
        HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout);
        HttpConnectionParams.setTcpNoDelay(httpParams, true);
        HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);
 
        HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUserAgent(httpParams, "thinkfeed#gmail.com/version:"+VERSION);
 
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
 
        httpContext = new SyncBasicHttpContext(new BasicHttpContext());
        httpClient = new DefaultHttpClient(cm, httpParams);
        httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
            @Override 
            public void process(HttpRequest request, HttpContext context) {
                if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
                    request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
                } 
                for (String header : clientHeaderMap.keySet()) {
                    request.addHeader(header, clientHeaderMap.get(header));
                } 
            } 
        }); 
 
        httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
            @Override 
            public void process(HttpResponse response, HttpContext context) {