AbstractHttpClient getParams - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AbstractHttpClient getParams method.

This code example shows how to use the following methods:getParams
     * Sets the User-Agent header to be sent with each request. By default, 
     * "Android Asynchronous Http Client/VERSION (http://loopj.com/android-async-http/)" is used. 
     * @param userAgent the string to use in the User-Agent header. 
     */ 
    public void setUserAgent(String userAgent) {
        HttpProtocolParams.setUserAgent(this.httpClient.getParams(), userAgent);
    } 
 
    /** 
     * Sets the connection time oout. By default, 10 seconds 
     * @param timeout the connect/socket timeout in milliseconds 
     */ 
    public void setTimeout(int timeout){
        final HttpParams httpParams = this.httpClient.getParams();
        ConnManagerParams.setTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
    } 
 
    /** 
8
CodeRank
This code example shows how to use the following methods:addRequestInterceptor, execute, getConnectionManager, getParams
		return responseStr.toString();
	} 
	 
	private DefaultHttpClient getHttpClient() {
		 
		DefaultHttpClient client = new DefaultHttpClient();
		 
		// I believe DefaultHttpClient handles redirects by default anyway 
		client.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
				Boolean.TRUE);
		 
		client.addRequestInterceptor(new HttpRequestInterceptor() {   
			public void process( 
					final HttpRequest request, 
                    final HttpContext context) throws HttpException, IOException {
				request.addHeader("Accept", "application/xml");
			} 
		}); 
		 
		SSLSocketFactory.getSocketFactory().setHostnameVerifier( SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER );

7
CodeRank
This code example shows how to use the following methods:addRequestInterceptor, addResponseInterceptor, getParams, setHttpRequestRetryHandler
        context.setHttpResponse(response);
        return context;
    } 
     
    private static DefaultHttpClient getHttpClient(HttpInvocationContext context) {
        DefaultHttpClient client = new DefaultHttpClient();
        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; 
            } 
        });   
        client.addRequestInterceptor(context);
        client.addResponseInterceptor(context);
        return client;
    } 
     
} 
7
CodeRank
This code example shows how to use the following methods:execute, getCredentialsProvider, getParams
 
    // Auth 
 
    private boolean checkAuth(String username, String password, URI uri) throws ClientProtocolException, IOException
    { 
        DefaultHttpClient httpClient = new DefaultHttpClient();
 
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "XWik");
        httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
        httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
 
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(username, password));
 
        HttpGet httpget = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpget);
 
        return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
    } 
 
    // Sync 
6
CodeRank
This code example shows how to use the following methods:getParams
This code example shows how to use the following methods:getCredentialsProvider, getParams, setCookieStore
6
CodeRank
This code example shows how to use the following methods:getParams
   * is used. 
   * 
   * @param userAgent the string to use in the User-Agent header. 
   */ 
  public void setUserAgent(String userAgent) {
    HttpProtocolParams.setUserAgent(this.httpClient.getParams(), userAgent);
  } 
 
  /** 
   * Sets the connection time oout. By default, 10 seconds 
   * 
   * @param timeout the connect/socket timeout in milliseconds 
   */ 
  public void setTimeout(int timeout) {
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setTimeout(httpParams, timeout);
    HttpConnectionParams.setSoTimeout(httpParams, timeout);
    HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
  } 
 
6
CodeRank
This code example shows how to use the following methods:getParams
        reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
 
        final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(config, reg);
 
        final DefaultHttpClient client = new DefaultHttpClient(manager, config);
        client.getParams().setParameter("http.socket.timeout", 30 * 1000);
        return client;
    } 
 
    @SuppressWarnings("deprecation") 
    public static String decodeSubscriptionURL(final String url) {
        if (url.startsWith("feed/")) {
            return "feed/" + URLDecoder.decode(url.substring(5));
        } else { 
            return url;
        } 
    } 
 
    @SuppressWarnings("deprecation") 
6
CodeRank
This code example shows how to use the following methods:execute, getConnectionManager, getCredentialsProvider, getParams
	protected static String USERNAME = "";
	protected static String PASSWORD = "";
	private static boolean isLogged = false;
 
	private static HttpResponse executeHttpRequest(HttpUriRequest request,boolean useAuthentication) throws ClientProtocolException, IOException {
		DefaultHttpClient client = new DefaultHttpClient();
		 
		HttpProtocolParams.setUseExpectContinue(client.getParams(), false);
		if (useAuthentication)
			client.getCredentialsProvider().setCredentials(
					new AuthScope(null, 80, "thounds","Digest"),
					new UsernamePasswordCredentials(USERNAME, PASSWORD));
		HttpResponse responce = client.execute(request);		
		client.getConnectionManager().shutdown();
		return responce;
	} 
 
	private static JSONObject httpResponseToJSONObject(HttpResponse response)
			throws IllegalStateException, IOException, JSONException { 
		BufferedReader in = new BufferedReader(new InputStreamReader(response
6
CodeRank
This code example shows how to use the following methods:getCredentialsProvider, getParams, setCookieStore
     */ 
    public BasicClient(String host, String username, String password, int portnum) {
    	if (portnum == 443) {
    		this.scheme = "https";
    	} 
        client = new DefaultHttpClient();
        client.getParams().setParameter(ClientPNames.DEFAULT_HOST, new HttpHost(host, portnum, scheme));
        HttpProtocolParams.setUserAgent(client.getParams(), "InSites Java Connection");
        client.setCookieStore(new BasicCookieStore());
 
        client.getCredentialsProvider().setCredentials(new AuthScope(host, portnum), new UsernamePasswordCredentials(username, password));
         
        //We can not use org.apache.commons.codec.binary.Base64, so use the equivalent Android encoder 
        authHeaderValue = "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP);
    } 
 
    /** 
     * Consumes an InputStream, and builds a String representation of the data. 
     *  
     * @param in	an InputStream to convert 
6
CodeRank

Related AbstractHttpClient getParams Questions & Answers: