Code example for HttpURLConnection

Methods: setConnectTimeout, setDoInput, setReadTimeout, setRequestMethod

0
        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 
     * frustrating bugs. In particular, calling close() on a readable 
     * InputStream could poison the connection pool. Work around this by 
     * disabling connection pooling. 
     */ 
    public static void disableConnectionReuseIfNecessary() { 
        // HTTP connection reuse which was buggy pre-froyo 
        if (!isFroyoOrHigher()) {