Java HttpURLConnection getHeaderField() Method

The getHeaderField(int n) is the method of HttpURLConnection class. This method is used to get n header field. It returns 0 when it is a special header field, i.e., 0th header field. This method can also be used with the getHeaderFieldKey method to get all the headers of the message.

Syntax

Parameter

n - an index, where n>=0.

Returns

It returns the nth header field, else it returns null.

Example 1

Test it Now

Output:

Header field 0:HTTP/1.1 200 200
Header field 1:Thu, 29 Nov 2018 15:19:27 GMT
getFollowRedirects : true
connection disconnected

Example 2

Test it Now

Output:

www.mysql.com
Header field 0:HTTP/1.1 200 OK
Header field 1:Thu, 29 Nov 2018 15:25:37 GMT
www.oracle.com
Header field 0:HTTP/1.1 200 OK
Header field 1:Oracle-HTTP-Server
getFollowRedirects : true
connection disconnected




Latest Courses