Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class JavaHttpURLConnectionDisconnectMethodExample1 { //Starting the main method... public static void main(String h[]) throws IOException { //starting the try block try { String link_url1 ; link_url1="https://www.javatpoint.com"; URL obj1 = new URL(link_url1); //URL Connection Created... HttpURLConnection con1 = (HttpURLConnection) obj1.openConnection(); //Http URL Connection Created... int r_code = con1.getResponseCode(); // it is use to get the status code from HTTP response message System.out.println("status code from HTTP response message : "+r_code); con1.disconnect(); // disconnecting the connection System.out.println("connection disconnected"); } catch (Exception e) { System.out.println( e); } } }
Output