Code example for DefaultHttpClient

Methods: getParams, setHttpRequestRetryHandler

0
public class SimpleHttpClient { 
 
    private DefaultHttpClient client;
 
    public SimpleHttpClient() { 
        this.client = new DefaultHttpClient(new ThreadSafeClientConnManager());
        HttpParams params = client.getParams();
        HttpConnectionParams.setConnectionTimeout(params, 30000);
        HttpConnectionParams.setSoTimeout(params, 30000);
        client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
            public boolean retryRequest(IOException e, int i, HttpContext httpContext) {
                return false; 
            } 
        }); 
    } 
 
    /** 
     * Send a HTTP GET request to the specified URL 
     * 
     * @param url     Target endpoint URL 
     * @param headers Any HTTP headers that should be added to the request