Code example for HttpURLConnection

Methods: getResponseCodesetInstanceFollowRedirectssetRequestMethodgetInputStreamsetUseCaches

0
		if (!(conn instanceof HttpURLConnection))
			throw new IOException("Not an HTTP connection");
 
		try { 
			HttpURLConnection httpConn = (HttpURLConnection) conn;
			httpConn.setInstanceFollowRedirects(true);
			httpConn.setRequestMethod("GET");
			httpConn.setUseCaches(true);
 
			/* 
			 * Object content = httpConn.getContent(); if( content instanceof 
			 * Bitmap ){ Bitmap bitmap = (Bitmap)content; } 
			 */ 
 
			response = httpConn.getResponseCode();
			if (response == HttpURLConnection.HTTP_OK) {
				inputStream = httpConn.getInputStream();
			} 
		} catch (Exception ex) {
			throw new IOException("Error connecting " + ex);
		} 
		return inputStream;
Stop searching for code, let great code find you!  Add Codota to your java IDE