Code example for HttpURLConnection

Methods: addRequestPropertysetConnectTimeoutsetReadTimeout

0
        try { 
            con = (HttpURLConnection) newUrl.openConnection();
        } catch (IOException e) {
            return null; 
        } 
        con.setReadTimeout(60000);
        con.setConnectTimeout(60000);
        con.addRequestProperty("Expect", "100-continue");
        con.addRequestProperty("Authorization",
                               "Basic "+Base64.encodeToString((this.username + ":" + this.password).getBytes(),
                                                      Base64.NO_WRAP));
        return con;
	} 
 
	private InputStream getUrlStream(String url) throws IOException, CertificateException {
        Log.i("MobileOrg", "Fetching " + url);
        HttpURLConnection con = this.createConnection(url);
        con.setRequestMethod("GET");
        con.setDoInput(true);
        con.connect();
Stop searching for code, let great code find you!  Add Codota to your java IDE