Android Http Get requestGet(String url)

Here you can find the source of requestGet(String url)

Description

Sets up and opens a new HttpURLConnection to perform a HTTP GET request.

License

Apache License

Parameter

Parameter Description
url The url of the request

Exception

Parameter Description
IOException If something went wrong during establishing connection

Return

The setup HttpURLConnection object

Declaration

private static HttpURLConnection requestGet(String url)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    /**//from  ww w  . j ava2s  .c o m
     * Sets up and opens a new HttpURLConnection to perform a HTTP GET request. 
     * One can then directly call the {@link HttpURLConnection#connect()} and
     * read the response code and read the response through its InputStream.
     * 
     * @param url
     *       The url of the request
     * @return
     *       The setup HttpURLConnection object
     * @throws IOException
     *       If something went wrong during establishing connection
     */
    private static HttpURLConnection requestGet(String url)
            throws IOException {
        URL getUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) getUrl
                .openConnection();
        conn.setReadTimeout(10000);
        conn.setConnectTimeout(15000);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        return conn;
    }
}

Related

  1. request(String url)
  2. executeHttpGet(String url)
  3. executeHttpPost(String url, ArrayList postParameters)
  4. getHTTP(String... params)
  5. handleURLEncodedResponse(HttpResponse response)