Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class JavaHttpURLConnectiongetFollowRedirectsExample2 { //Starting the main method... public static void main(String h[]) throws IOException { //starting the try block try { String link_url1, link_url2; link_url1="https://www.mysql.com"; link_url2="https://www.oracle.com"; URL obj1 = new URL(link_url1); //URL Connection Created... URL obj2 = new URL(link_url2); HttpURLConnection con1 = (HttpURLConnection) obj1.openConnection(); //Http URL Connection Created... HttpURLConnection con2 = (HttpURLConnection) obj2.openConnection(); con1.connect(); HttpURLConnection.setFollowRedirects(true); System.out.println("www.mysql.com"); System.out.println("getFollowRedirects :" + con1.getFollowRedirects()); System.out.println("www.oracle.com"); System.out.println("getFollowRedirects :" + con2.getFollowRedirects()); con1.setConnectTimeout(1000); con1.disconnect(); System.out.println("connection disconnected"); } catch (Exception e) { System.out.println( e); } } }
Output