Java HttpURLConnection getHeaderField() MethodLast Updated : 17 Mar 2025 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. SyntaxParametern - an index, where n>=0. ReturnsIt returns the nth header field, else it returns null. Example 1Output: Header field 0:HTTP/1.1 200 200 Header field 1:Thu, 29 Nov 2018 15:19:27 GMT getFollowRedirects : true connection disconnected Example 2Output: 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 Next TopicJava HttpURLConnection class |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India