Android AbstractHttpClient - top ranked examples from Open Source projects

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

This code example shows how to use the following methods: execute
	{ 
		if (uri.indexOf("http://") == -1)
			uri = "http://" + uri;
		boolean reached = isAvailable();
		try { 
			DefaultHttpClient httpclient = new DefaultHttpClient();
			HttpGet httpget = new HttpGet(uri);
			httpclient.execute(httpget);			
		} catch (Exception e) { 
			reached = false;
		} 
		return reached;
	} 
	 
	 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: addRequestInterceptor, addResponseInterceptor, setHttpRequestRetryHandler
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getConnectionManager, setParams, setRoutePlanner, setRedirectStrategy
  public HttpClient getHttpClient() {
    return httpClient;
  } 
 
  public HttpClient getGridHttpClient(int connection_timeout, int socket_timeout) {
    DefaultHttpClient gridClient = new DefaultHttpClient(gridClientConnectionManager);
    gridClient.setRedirectStrategy(new MyRedirectHandler());
    gridClient.setParams(getGridHttpParams(connection_timeout, socket_timeout));
    gridClient.setRoutePlanner(
        getRoutePlanner(gridClient.getConnectionManager().getSchemeRegistry()));
    gridClient.getConnectionManager().closeIdleConnections(100, TimeUnit.MILLISECONDS);
 
    return gridClient;
  } 
 
  public HttpParams getHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setSoReuseaddr(params, true);
    HttpConnectionParams.setConnectionTimeout(params, 120 * 1000);
    HttpConnectionParams.setSoTimeout(params, TIMEOUT_THREE_HOURS);
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execute, getCredentialsProvider
 
    @Test 
    public void testSuccessfulAuthentication(@ArquillianResource URL webAppURL) throws Exception {
        DefaultHttpClient httpClient = createHttpClient(webAppURL, "User", "User");
 
        HttpResponse httpResponse = httpClient.execute(new HttpGet(webAppURL.toURI()));
 
        assertEquals(200, httpResponse.getStatusLine().getStatusCode());
 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
 
        httpResponse.getEntity().writeTo(bos);
 
        assertTrue(new String(bos.toByteArray()).contains("Welcome"));
    } 
 
    @Test 
    public void testUnsuccessfulAuthentication(@ArquillianResource URL webAppURL) throws Exception {
        DefaultHttpClient httpClient = createHttpClient(webAppURL, "Invalid User", "User");
 

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execute
        Assert.assertEquals("OrderModel{id=5}", EntityUtils.toString(result.getEntity()));
    } 
 
    @Test 
    public void testInvalidRequest() throws Exception { 
        DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
 
        HttpGet get = new HttpGet(url + "myjaxrs/order/11");
        HttpResponse result = client.execute(get);
        result = client.execute(get);
 
        Assert.assertEquals("Parameter constraint violated", 400, result.getStatusLine().getStatusCode());
    } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execute
    } 
 
    @Test 
    public void testCookieSetCorrectly() throws Exception { 
        log.info("testCookieSetCorrectly()"); 
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(cookieReadURL.toURI() + "CookieReadServlet"));
        if (response.getEntity() != null)
            response.getEntity().getContent().close();
 
        log.info("Sending request with cookie"); 
        response = httpclient.execute(new HttpPost(cookieReadURL.toURI() + "CookieReadServlet"));
    } 
 
    @Test 
    public void testCookieRetrievedCorrectly() throws Exception { 
        log.info("testCookieRetrievedCorrectly()"); 
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(cookieURL.toURI() + "CookieServlet"));
 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execute, getConnectionManager
 
    // create Threadsafe Client 
    ClientConnectionManager connMgr = new PoolingClientConnectionManager(supportedSchemes);
 
    // Create default httpClient 
    DefaultHttpClient httpclient = new DefaultHttpClient(connMgr, params);
 
    // Set Path 
    HttpGet httpget = new HttpGet(uri());
 
    if(log.isDebugEnabled()) 
      log.debug("executing request to " + targetHost);
 
    // Executes a request to the target using the default context. 
    HttpResponse httpResponse = httpclient.execute(targetHost, httpget);
 
    // Set Response 
    setResponse(httpResponse);
 
    if (response().getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: addRequestInterceptor, execute, getCredentialsProvider
			sr.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
			sr.register(new Scheme("https", new IgnoreSSLSocketFactory(), 443));
			ClientConnectionManager cm = new SingleClientConnManager(params, sr);
			h = new DefaultHttpClient(cm, params);
		} else { 
			h = new DefaultHttpClient(params);
		} 
		h.getCredentialsProvider().setCredentials(AuthScope.ANY, auth);
 
		BasicHttpContext localcontext = new BasicHttpContext();
		BasicScheme basicAuth = new BasicScheme();
		localcontext.setAttribute("preemptive-auth", basicAuth);
		h.addRequestInterceptor(new PreemptiveAuth(), 0);
 
		return h.execute(new HttpHost(host, port, scheme), req);
	} 
 
	public static HttpResponse get(URI uri, String username, String password, boolean badcert) throws Exception {
		HttpGet g = new HttpGet(uri);
		Log.v(TAG, "Get: " + uri);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execute
 
	public String sendGet(String url) {
		httpGet = new HttpGet(url);
 
		try { 
			response = httpClient.execute(httpGet);
		} catch (Throwable e) {
			Log.e(TAG, "sendGet exception: ", e);
		} 
 
		// we assume that the response body contains the error message 
		try { 
			if (null == response)
				return null; 
			ret = EntityUtils.toString(response.getEntity());
		} catch (Throwable e) {
			Log.e(TAG, "sendGet exception: ", e);
		} 
 
		return ret;
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execute
    @Test 
    public void accessWSDLWithValidUsernameAndPassord() throws Exception { 
        URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");
        String encoding = Base64Encoder.encode("user1:password1");
 
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(wsdlURL.toString());
        httpget.setHeader("Authorization", "Basic " + encoding);
        HttpResponse response = httpclient.execute(httpget);
 
        String text = Utils.getContent(response);
        Assert.assertTrue("Response doesn't contain wsdl file", text.contains("wsdl:binding"));
 
    } 
 
    @Test 
    public void accessWSDLWithValidUsernameAndPassordButInvalidRole() throws Exception { 
        URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");
        String encoding = Base64Encoder.encode("user2:password2");
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android AbstractHttpClient Questions & Answers:

See Code Examples for Android AbstractHttpClient Methods: