In this section, we are going to illustrate you how to get the Http Headers. Here, we are using the URL class which points the resource. In order to make a communication link between the application and a URL, we have used the class URLConnection.
url.openConnection()- This method of URL class returns a
URLConnection object that represents a connection referred to by the
conn.getHeaderFieldKey(i)- This method returns the key for the header field.
conn.getHeaderField(i)- This method returns the value for the header field.
Here is the code of GetHttpHeaders.java
To run the above example, first of all start the tomcat as you have taken the resource http://localhost:8080. Then compile the class and execute the example, you will get the Http Headers on the console.
Liked it! Share this Tutorial