Code example for HttpURLConnection

Methods: connect, getInputStream, setConnectTimeout, setDoInput, setReadTimeout, setRequestMethod

0
     * Returns an {@link InputStream} using {@link HttpURLConnection} to connect 
     * to the given URL. 
     */ 
    public static InputStream downloadUrl(String urlString) throws IOException {
        HttpURLConnection conn = buildHttpUrlConnection(urlString);
        conn.connect();
 
        InputStream stream = conn.getInputStream();
        return stream;
    } 
 
    /** 
     * Returns an {@link HttpURLConnection} using sensible default settings for 
     * mobile and taking care of buggy behavior prior to Froyo. 
     */ 
    public static HttpURLConnection buildHttpUrlConnection(String urlString)
            throws MalformedURLException, IOException { 
        AndroidUtils.disableConnectionReuseIfNecessary(); 
 
        URL url = new URL(urlString);
 
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setDoInput(true);
        conn.setRequestMethod("GET");
        return conn;
    } 
 
    /** 
     * Prior to Android 2.2 (Froyo), {@link HttpURLConnection} had some