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

This code example shows how to use the following methods:
  void retrieveSupplementalInfo() throws IOException, InterruptedException { 
 
    String encodedProductID = URLEncoder.encode(productID, "UTF-8");
    String uri = BASE_PRODUCT_URI + encodedProductID;
 
    HttpUriRequest head = new HttpGet(uri);
    AndroidHttpClient client = AndroidHttpClient.newInstance(null);
    HttpResponse response = client.execute(head);
    int status = response.getStatusLine().getStatusCode();
    if (status != 200) {
      return; 
    } 
 
    String content = consume(response.getEntity());
    Matcher matcher = PRODUCT_NAME_PRICE_PATTERN.matcher(content);
    if (matcher.find()) {
      append(matcher.group(1));
      append(matcher.group(2));
    } 
    setLink(uri);
Full Snippet Info
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader, getParams
        if (DEBUG) Log.d(TAG, "Downloading XTRA data from " + url);
 
        AndroidHttpClient client = null;
        try { 
            client = AndroidHttpClient.newInstance("Android");
            HttpUriRequest req = new HttpGet(url);
 
            if (isProxySet) {
                HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
            } 
 
            req.addHeader(
                    "Accept", 
                    "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); 
 
            req.addHeader(
                    "x-wap-profile", 
                    "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); 
 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        } 
 
        @Override 
        public HttpResponse call() throws Exception {
            try { 
                return client.execute(new HttpGet(url));
            } finally { 
                client.getConnectionManager().closeExpiredConnections();
            } 
        } 
    } 
} 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
     * @param graceTime 
     * @return 
     * @throws IOException 
     */ 
    public static HttpResponse tryGet(final HttpClient client, final String url, final long graceTime) throws IOException {
        return tryGet(client, new HttpGet(url));
    } 
 
    /** 
     * Tries a get on the provided client consuming the request body. 
     * 
     * @param client 
     * @param url 
     * @return response body as string 
     * @throws IOException 
     */ 
    public static String tryGetAndConsume(final HttpClient client, final String url) throws IOException {
        // Get the response 
        HttpResponse response = tryGet(client, url);
 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        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
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        } 
 
        ((DefaultHttpClient) httpClient).getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY),
                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; 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
   @RunAsClient 
   @Test 
   public void servletDatasourceInjectionTest(){ 
      DefaultHttpClient httpclient = new DefaultHttpClient();
      HttpResponse response;
      HttpGet httpget = new HttpGet(baseURL.toString());
 
      String responseText;
      try { 
         response = httpclient.execute(httpget);
         HttpEntity entity = response.getEntity();
         responseText = EntityUtils.toString(entity);
      } catch (IOException ex) {
         throw new RuntimeException("No response from servlet!", ex);
      } 
 
      assertTrue("Masked datasource not injected correctly to the servlet! Servlet response text: " + responseText, responseText.contains("true"));
   } 
 
} 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
            Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" +
                    modeString, e);
            return new LinkedList<String>();
        } 
 
        HttpGet httpRequest = new HttpGet(url.toString());
        ResponseHandler<LinkedList<String>> handler = new ResponseHandler<LinkedList<String>>() {
            @Override 
            public LinkedList<String> handleResponse(HttpResponse response)
                    throws IOException { 
                LinkedList<String> lines = new LinkedList<String>();
 
                if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                    return lines;
                } 
                HttpEntity entity = response.getEntity();
                if (entity == null) {
                    return lines;
                } 
 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader, getParams
        if (DEBUG) Log.d(TAG, "Downloading XTRA data from " + url);
 
        AndroidHttpClient client = null;
        try { 
            client = AndroidHttpClient.newInstance("Android");
            HttpUriRequest req = new HttpGet(url);
 
            if (isProxySet) {
                HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
            } 
 
            req.addHeader(
                    "Accept", 
                    "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); 
 
            req.addHeader(
                    "x-wap-profile", 
                    "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); 
 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android HttpGet Questions & Answers:

Other Android HttpGet Examples

65:						url += "?" + paramString;
66:					}
67:					HttpGet httpGet = new HttpGet(url);
68:	
69:					httpResponse = httpClient.execute(httpGet);
-
65:						url += "?" + paramString;
66:					}
67:					HttpGet httpGet = new HttpGet(url);
68:	
69:					httpResponse = httpClient.execute(httpGet);

Read More

70:						url += "?" + paramString;
71:					}
72:					HttpGet httpGet = new HttpGet(url);
73:	
74:					httpResponse = httpClient.execute(httpGet);
-
70:						url += "?" + paramString;
71:					}
72:					HttpGet httpGet = new HttpGet(url);
73:	
74:					httpResponse = httpClient.execute(httpGet);

Read More

56:					String paramString = URLEncodedUtils.format(params, "utf-8");
57:					url += "?" + paramString;
58:					HttpGet httpGet = new HttpGet(url);
59:	
60:					HttpResponse httpResponse = httpClient.execute(httpGet);
-
56:					String paramString = URLEncodedUtils.format(params, "utf-8");
57:					url += "?" + paramString;
58:					HttpGet httpGet = new HttpGet(url);
59:	
60:					HttpResponse httpResponse = httpClient.execute(httpGet);

Read More

See Code Examples for Android HttpGet Methods: