Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class JavaHttpURLConnectionDisconnectMethodExample2{ //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... con1.connect(); for(int a=1;a<=8;a++) { System.out.println(con1.getHeaderFieldKey(a)+" = "+con1.getHeaderField(a)); con1.disconnect(); System.out.println("Connection disconnected"); // disconnecting the connection } } catch (Exception e) { System.out.println( e); } } }
Output