Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class JavaHttpURLConnectionGetErrorStreamMethodExample2 { //Starting the main method... public static void main(String h[]) throws IOException { //starting the try block try { String link_url ; link_url="https://www.facebook.com"; URL obj1 = new URL(link_url); //URL Connection Created... HttpURLConnection con1 = (HttpURLConnection) obj1.openConnection(); //Http URL Connection Created... con1.setConnectTimeout(1000); con1.connect(); System.out.println("Connection Established"); InputStream a; a = con1.getErrorStream(); System.out.println("Error Stream : "+a); System.out.println("Header field 1:" + con1.getHeaderField(1)); con1.disconnect(); System.out.println("Connection disconnected"); } catch (Exception e) { System.out.println( e); } } }
Output