URLConnection getHeaderField Example
URLConnection class getHeaderField example. This example shows you how to use getHeaderField method.
URLConnection class getHeaderField example. public String getHeaderField(int n) Returns the value for the nth header field. It returns null if there are fewer than n+1fields. This method can be used in conjunction with the getHeaderFieldKey method to iterate through all the headers in the message.
Here is the code
/*
* @ # GetHeaderField.java
* A class repersenting use to GetHeaderField
* method of URLConnection class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
public class GetHeaderField {
public static void main(String args[]) throws Exception {
SocketAddress socketAddress =
new InetSocketAddress("192.168.10.80", 9090);
Proxy proxy = new Proxy(Proxy.Type.HTTP, socketAddress);
URL url = new URL("http://roseindia.net");
URLConnection connection = url.openConnection(proxy);
System.out.println("Header Field " +
connection.getHeaderField(1));
}
} |
Output
| Header Field Thu, 26 Jun 2008 12:08:27 GMT |
|