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

This code example shows how to use the following methods:execute, getConnectionManager
        } 
 
        @Override 
        public HttpResponse call() throws Exception {
            try { 
                return client.execute(new HttpGet(url));
            } finally { 
                client.getConnectionManager().closeExpiredConnections();
            } 
        } 
    } 
} 
7
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));
  } 
} 
7
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();
        } 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute
    return httpClient.getConnectionManager();
  } 
 
  @Implementation 
  public HttpResponse execute(HttpUriRequest httpUriRequest) throws IOException, ClientProtocolException {
    return httpClient.execute(httpUriRequest);
  } 
 
  @Implementation 
  public HttpResponse execute(HttpUriRequest httpUriRequest, HttpContext httpContext) throws IOException, ClientProtocolException {
    return httpClient.execute(httpUriRequest, httpContext);
  } 
 
  @Implementation 
  public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest) throws IOException, ClientProtocolException {
    return httpClient.execute(httpHost, httpRequest);
  } 
 
  @Implementation 
  public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws IOException, ClientProtocolException {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute
		else { 
			 
			ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
			nameValuePairs.add(new BasicNameValuePair("text", uploadstring));
			try{ 
				HttpClient httpclient = new DefaultHttpClient();
				String http = "http://";
				String controlIP = ((FrameworkAndroidApp) this.getApplication()).getcontrolIP();
				String path = ((FrameworkAndroidApp) this.getApplication()).getpath();
				String url = "/putfuncuploader.php";
				String uri = http.concat(controlIP);
				String postto1 = uri.concat(path);
				String postto = postto1.concat(url);
				HttpPost httppost = new HttpPost(postto);
				httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
				httpclient.execute(httppost);
				//HttpEntity entity = response.getEntity(); 
				//InputStream input = entity.getContent(); 
				}catch(Exception e){
 
				e.printStackTrace();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectionManager
   
  @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;
     
    try { 
      ResponseHandler<byte[]> responseHandler=new ByteArrayResponseHandler();
      byte[] responseBody=client.execute(getMethod, responseHandler);
      File output=new File(Environment.getExternalStorageDirectory(),
                          i.getData().getLastPathSegment());
       
      if (output.exists()) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute
                new UsernamePasswordCredentials(user, pass));
 
        HttpGet get = new HttpGet(url);
        HttpResponse hr;
        try { 
            hr = httpClient.execute(get);
        } catch (Exception e) {
            if (responseSubstring == null)
                return false; 
            else // in case substring is defined, rethrow exception so, we can easier analyze the cause 
                throw new Exception(e);
        } 
 
        int statusCode = hr.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            log.info("statusCode not expected. statusCode=" + statusCode + ", URL=" + url);
            return false; 
        } 
 
        if (responseSubstring == null) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute, getConnectionManager
		} 
		return m;
	} 
	 
	public void gendwz(String url, String alias) {
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://dwz.cn/create.php");
		post.getParams()
			.setParameter("url", url)
			.setParameter("alias", alias);
		try { 
			ResponseHandler<String> responseHandler = new BasicResponseHandler();
			String responseBody = client.execute(post, responseHandler);
			System.out.println(responseBody);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally { 
			client.getConnectionManager().shutdown();

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute
		if(pMinutes < 1 || pMinutes > AAS_MAXMINUTES) {
			throw new IllegalArgumentException("pMinutes must be between: 1 and " + AAS_MAXMINUTES);
		} 
 
		final String url = URL_AAS_EUROPE;
		final HttpClient httpClient = new DefaultHttpClient();
		//      httpClient.getParams().setParameter("http.socket.timeout", new Integer(1200000)); // 2min 
 
		final HttpPost request = new HttpPost(url);
 
		// create the multipart request and add the parts to it 
		final MultipartEntity requestEntity = AASRequestComposer.create(gp, pMinutes);
 
		request.setEntity(requestEntity);
 
		final HttpResponse response = httpClient.execute(request);
		final int status = response.getStatusLine().getStatusCode();
 
		if (status != HttpStatus.SC_OK) {
			throw new IOException();
		} else { 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectionManager
   
  @Override 
  public void onDestroy() { 
    super.onDestroy(); 
     
    client.getConnectionManager().shutdown();
  } 
   
  private void updateForecast(Location loc) {
    String url=String.format(format, loc.getLatitude(),
                             loc.getLongitude());
    HttpGet getMethod=new HttpGet(url);
     
    try { 
      ResponseHandler<String> responseHandler=new BasicResponseHandler();
      String responseBody=client.execute(getMethod,
                                         responseHandler);
      buildForecasts(responseBody);
       
      String page=generatePage();
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android HttpClient Questions & Answers:

Other Android HttpClient Examples

25:	
26:			// Creating HTTP client
27:			HttpClient httpClient = new DefaultHttpClient();
28:			// Creating HTTP Post
29:			HttpPost httpPost = new HttpPost(

Read More

See Code Examples for Android HttpClient Methods: