Android DefaultHttpClient - 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 DefaultHttpClient class.

This code example shows how to use the following methods:
 
@Implements(AndroidHttpClient.class)
public class ShadowAndroidHttpClient { 
  @RealObject private AndroidHttpClient client;
 
  private HttpClient httpClient = new DefaultHttpClient();
 
  @Implementation 
  public static AndroidHttpClient newInstance(String userAgent) {
    return Robolectric.newInstanceOf(AndroidHttpClient.class);
  } 
 
  @Implementation 
  public static AndroidHttpClient newInstance(String userAgent, Context context) {
    return Robolectric.newInstanceOf(AndroidHttpClient.class);
  } 
 
  @Implementation 
  public HttpParams getParams() {
    return httpClient.getParams();
Full Snippet Info
9
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: addRequestInterceptor, addResponseInterceptor, setHttpRequestRetryHandler
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
   
  @Override 
  public void onCreate() { 
    super.onCreate(); 
     
    client=new DefaultHttpClient();
  } 
   
  @Override 
  public void onDestroy() { 
    super.onDestroy(); 
     
    client.getConnectionManager().shutdown();
  } 
 
  @Override  
  public void onHandleIntent(Intent i) {
    HttpGet getMethod=new HttpGet(i.getData().toString());
    int result=Activity.RESULT_CANCELED;
     
Full Snippet Info
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execute
    WebElement body = driver.findElement(By.xpath("//body"));
    assertEquals(FILE_CONTENTS, body.getText());
  } 
 
  private void assertUrlHasContentType(String url, String appcacheMimeType) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response;
 
    try { 
      response = httpclient.execute(httpget);
    } catch (Throwable t) {
      throw Throwables.propagate(t);
    } 
 
    Header[] contentTypeHeaders = response.getHeaders("Content-Type");
    assertEquals(1, contentTypeHeaders.length);
    assertTrue(contentTypeHeaders[0].getValue().contains(appcacheMimeType));
  } 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    @ContainerResource 
    private ManagementClient managementClient;
    private static ManagementClient mc;
 
    DefaultHttpClient httpclient = new DefaultHttpClient();
 
    @Before 
    public void setup() throws Exception { 
        if (mc == null) {
            mc = managementClient;
            //add the reverse proxy 
            ModelNode op = new ModelNode();
            ModelNode addr = new ModelNode();
            addr.add(ModelDescriptionConstants.SUBSYSTEM, "undertow");
            addr.add("configuration", "handler");
            addr.add("reverse-proxy", "myproxy");
            op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
            op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
            ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execute
                 
        try { 
            HttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setSoTimeout(httpParams, SOCKET_TIMEOUT);
            HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT);
            HttpClient httpClient = new DefaultHttpClient(httpParams);
            HttpGet httpget = new HttpGet(TIMER_URL);
            HttpResponse response = httpClient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                time = Long.parseLong(EntityUtils.toString(entity),10);
                logger.debug("Got remote timestamp {}", time);
            } 
        } catch (IOException e) {
            logger.warn("Error obtaining the synchronized remote timestamp, defaulting to the local one",e);
        } 
         
        if (time == -1) {
            time = System.currentTimeMillis();
        } 
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java

Related Android DefaultHttpClient Questions & Answers:

Other Android DefaultHttpClient Examples

3:			try {
4:				// defaultHttpClient
5:				DefaultHttpClient httpClient = new DefaultHttpClient();
6:				HttpPost httpPost = new HttpPost(url);
7:	
-
3:			try {
4:				// defaultHttpClient
5:				DefaultHttpClient httpClient = new DefaultHttpClient();
6:				HttpPost httpPost = new HttpPost(url);
7:

Read More

43:					// request method is POST
44:					// defaultHttpClient
45:					DefaultHttpClient httpClient = new DefaultHttpClient();
46:					HttpPost httpPost = new HttpPost(url);
47:					httpPost.setEntity(new UrlEncodedFormEntity(params));
-
43:					// request method is POST
44:					// defaultHttpClient
45:					DefaultHttpClient httpClient = new DefaultHttpClient();
46:					HttpPost httpPost = new HttpPost(url);
47:					httpPost.setEntity(new UrlEncodedFormEntity(params));
-
53:				} else if (method == "GET") {
54:					// request method is GET
55:					DefaultHttpClient httpClient = new DefaultHttpClient();
56:					String paramString = URLEncodedUtils.format(params, "utf-8");
57:					url += "?" + paramString;
-
53:				} else if (method == "GET") {
54:					// request method is GET
55:					DefaultHttpClient httpClient = new DefaultHttpClient();
56:					String paramString = URLEncodedUtils.format(params, "utf-8");
57:					url += "?" + paramString;

Read More

44:					// defaultHttpClient
45:					DefaultHttpClient httpClient = new DefaultHttpClient();
46:					HttpPost httpPost = new HttpPost(url);
47:					httpPost.setEntity(new UrlEncodedFormEntity(params));
48:	
-
44:					// defaultHttpClient
45:					DefaultHttpClient httpClient = new DefaultHttpClient();
46:					HttpPost httpPost = new HttpPost(url);
47:					httpPost.setEntity(new UrlEncodedFormEntity(params));
48:	
-
54:					// request method is GET
55:					DefaultHttpClient httpClient = new DefaultHttpClient();
56:					String paramString = URLEncodedUtils.format(params, "utf-8");
57:					url += "?" + paramString;
58:					HttpGet httpGet = new HttpGet(url);
-
54:					// request method is GET
55:					DefaultHttpClient httpClient = new DefaultHttpClient();
56:					String paramString = URLEncodedUtils.format(params, "utf-8");
57:					url += "?" + paramString;
58:					HttpGet httpGet = new HttpGet(url);

Read More

See Code Examples for Android DefaultHttpClient Methods:
  • Animation
     (android.view.animation.Animation)
  • Bitmap
     (android.graphics.Bitmap)
  • Bundle
     (android.os.Bundle)
  • Fragment
     (android.app.Fragment)
  • HttpPost
     (org.apache.http.client.methods.HttpPost)
  • Logger
     (com.facebook.internal.Logger)
  • Matrix
     (android.graphics.Matrix)
  • Typeface
     (android.graphics.Typeface)
  • Uri
     (android.net.Uri)
  • VideoView
     (android.widget.VideoView)