0% found this document useful (0 votes)
12 views

HTTP Url Connection Demo

This Java code connects to a URL, prints the HTTP response headers, and disconnects from the URL. It creates a URL object, opens an HTTP connection, prints 8 header fields in a for loop, and disconnects from the connection.

Uploaded by

Sivapriya P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

HTTP Url Connection Demo

This Java code connects to a URL, prints the HTTP response headers, and disconnects from the URL. It creates a URL object, opens an HTTP connection, prints 8 header fields in a for loop, and disconnects from the connection.

Uploaded by

Sivapriya P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.io.

*;
import java.net.*;
public class HttpURLConnectionDemo{
public static void main(String[] args){
try{
URL url=new URL("http://www.javatpoint.com/java-tutorial");
HttpURLConnection huc=(HttpURLConnection)url.openConnection();
for(int i=1;i<=8;i++){
System.out.println(huc.getHeaderFieldKey(i)+" = "+huc.getHeaderField(i));
}
huc.disconnect();
}catch(Exception e){System.out.println(e);}
}
}

You might also like