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

This code example shows how to use the following methods:
 
  private static String unredirect(String uri) throws IOException {
    if (!isRedirector(uri)) {
      return uri;
    } 
    HttpUriRequest head = new HttpHead(uri);
    AndroidHttpClient client = AndroidHttpClient.newInstance(null);
    HttpResponse response = client.execute(head);
    int status = response.getStatusLine().getStatusCode();
    if (status == 301 || status == 302) {
      Header redirect = response.getFirstHeader("Location");
      if (redirect != null) {
        String location = redirect.getValue();
        if (location != null) {
          return location;
        } 
      } 
    } 
    return uri;
  } 
6
CodeRank
This code example shows how to use the following methods:
 
  private static String unredirect(String uri) throws IOException {
    if (!isRedirector(uri)) {
      return uri;
    } 
    HttpUriRequest head = new HttpHead(uri);
    AndroidHttpClient client = AndroidHttpClient.newInstance(null);
    HttpResponse response = client.execute(head);
    int status = response.getStatusLine().getStatusCode();
    if (status == 301 || status == 302) {
      Header redirect = response.getFirstHeader("Location");
      if (redirect != null) {
        String location = redirect.getValue();
        if (location != null) {
          return location;
        } 
      } 
    } 
    return uri;
  } 
5
CodeRank
This code example shows how to use the following methods:getURI
   * @return time (milliseconds since epoch). 
   * 
   * @throws IOException if an I/O error occurs. 
   */ 
  public long getNetworkTime() throws IOException { 
    HttpHead request = new HttpHead(URL);
    Log.i(LOG_TAG, "Sending request to " + request.getURI());
    HttpResponse httpResponse;
    try { 
      httpResponse = mHttpClient.execute(request);
    } catch (ClientProtocolException e) {
      throw new IOException(String.valueOf(e));
    } catch (IOException e) {
      throw new IOException("Failed due to connectivity issues: " + e);
    } 
 
    try { 
      Header dateHeader = httpResponse.getLastHeader("Date");
      Log.i(LOG_TAG, "Received response with Date header: " + dateHeader);
      if (dateHeader == null) {
5
CodeRank
This code example shows how to use the following methods:
	 
	public void checkURL(CheckerLink link) throws IOException {
		//build a HTTP getter for the  
		HttpClient client = new DefaultHttpClient();
		//build a HEAD request for the url 
		HttpHead h = new HttpHead(link.getURL().toString());
		//get head 
		HttpResponse resp = client.execute(h);
		 
		//find out how long the document is 
		Header clen = resp.getFirstHeader("Content-Length");
		 
		 
		long contentLength;
		try{ 
			contentLength = Long.valueOf(clen.getValue());
		}catch(Exception e){
			contentLength = -1;
		} 
		String status  = 
5
CodeRank
This code example shows how to use the following methods:
 
  private static String unredirect(String uri) throws IOException {
    if (!isRedirector(uri)) {
      return uri;
    } 
    HttpUriRequest head = new HttpHead(uri);
    AndroidHttpClient client = AndroidHttpClient.newInstance(null);
    HttpResponse response = client.execute(head);
    int status = response.getStatusLine().getStatusCode();
    if (status == 301 || status == 302) {
      Header redirect = response.getFirstHeader("Location");
      if (redirect != null) {
        String location = redirect.getValue();
        if (location != null) {
          return location;
        } 
      } 
    } 
    return uri;
  } 
5
CodeRank
This code example shows how to use the following methods:
 
    private static String unredirect(String uri) throws IOException {
        if (!isRedirector(uri)) {
            return uri;
        } 
        HttpUriRequest head = new HttpHead(uri);
        AndroidHttpClient client = AndroidHttpClient.newInstance(null);
        HttpResponse response = client.execute(head);
        int status = response.getStatusLine().getStatusCode();
        if (status == 301 || status == 302) {
            Header redirect = response.getFirstHeader("Location");
            if (redirect != null) {
                String location = redirect.getValue();
                if (location != null) {
                    return location;
                } 
            } 
        } 
        return uri;
    } 
5
CodeRank
This code example shows how to use the following methods:
 
	private static String unredirect(String uri) throws IOException {
		if (!isRedirector(uri)) {
			return uri;
		} 
		HttpUriRequest head = new HttpHead(uri);
		AndroidHttpClient client = AndroidHttpClient.newInstance(null);
		HttpResponse response = client.execute(head);
		int status = response.getStatusLine().getStatusCode();
		if (status == 301 || status == 302) {
			Header redirect = response.getFirstHeader("Location");
			if (redirect != null) {
				String location = redirect.getValue();
				if (location != null) {
					return location;
				} 
			} 
		} 
		return uri;
	} 
5
CodeRank
This code example shows how to use the following methods:
	public static HttpResponse getHeaders(String url, String authUser, String authPass, HttpClient client)
	{ 
		HttpResponse response = null;
		try 
		{ 
			HttpHead request = new HttpHead(url);
			addBasicAuthHeader(request, authUser, authPass);
		    response = client.execute(request);
		} 
		catch(Exception ex) { }
		return response;
	} 
	 
	/** 
	 * Gets the underlying stream from an HttpResponse object 
	 * @param url - The address of the resource 
	 * @param context - Context such as an activity or application context for retrieving the single instance HttpClient of the app 
	 * @return InputStream object 
	 */ 
	public static InputStream getInputStream(String url, HttpClient client)
4
CodeRank
This code example shows how to use the following methods:
        InputStream instream = entity.getContent();
        return instream;
    } 
 
    public static void testUrl(String url) throws ClientProtocolException, IOException {
        HttpHead head = new HttpHead(url);
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(head);
 
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == 404) {
            throw new FileNotFoundException();
        } 
 
        if (status.getStatusCode() != 200) {
            throw new RuntimeException("Could not get URL: " + status.getStatusCode() + ": "
                    + status.getReasonPhrase());
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
        req.setHeader(DATE_HEADER, DateFormat.format("E, dd MMM yyyy hh:mm:ss zz", g).toString());
    } 
 
 
    public static final HttpHead createOpenRosaHttpHead(URI uri) {
        HttpHead req = new HttpHead(uri);
        setOpenRosaHeaders(req);
        return req;
    } 
 
 
    public static final HttpGet createOpenRosaHttpGet(URI uri) {
        return createOpenRosaHttpGet(uri, "");
    } 
 
 
    public static final HttpGet createOpenRosaHttpGet(URI uri, String auth) {
        HttpGet req = new HttpGet();
        setOpenRosaHeaders(req);
        setGoogleHeaders(req, auth);
3
CodeRank

Related Android HttpHead Questions & Answers:

See Code Examples for Android HttpHead Methods: