Java API Tutorial - Java URLConnection .getHeaderField (String name)








Syntax

URLConnection.getHeaderField(String name) has the following syntax.

public String getHeaderField(String name)

Example

In the following code shows how to use URLConnection.getHeaderField(String name) method.

/*ww w. j a v  a  2 s .co  m*/
import java.net.URL;
import java.net.URLConnection;

public class Main{
  public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    URLConnection httpCon = (URLConnection) url.openConnection();

    String s = httpCon.getHeaderField("Set-Cookie");
    System.out.println(s);

 }
}

The code above generates the following result.