Header Viewer : URLConnection « Network « Java Tutorial






import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

public class MainClass {

  public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    System.out.println("Content-type: " + uc.getContentType());
    System.out.println("Content-encoding: " + uc.getContentEncoding());
    System.out.println("Date: " + new Date(uc.getDate()));
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
    System.out.println("Expiration date: " + new Date(uc.getExpiration()));
    System.out.println("Content-length: " + uc.getContentLength());
  }

}
Content-type: text/html
Content-encoding: null
Date: Thu May 24 18:41:00 PDT 2007
Last modified: Fri May 18 08:20:08 PDT 2007
Expiration date: Wed Dec 31 16:00:00 PST 1969
Content-length: 345648








19.5.URLConnection
19.5.1.java.net.URLConnection
19.5.2.URLConnection.openStream is more powerful than URL.openStream
19.5.3.Header Viewer
19.5.4.Sending a POST Request with Parameters From a Java Class
19.5.5.Downloading a web page using URL and URLConnection classes
19.5.6.Get response header from HTTP request
19.5.7.Getting the Response Headers from an HTTP Connection
19.5.8.Getting the Cookies from an HTTP Connection
19.5.9.Preventing Automatic Redirects in a HTTP Connection
19.5.10.Sending a Cookie to an HTTP Server
19.5.11.Writing to a Web server
19.5.12.Identify yourself using HTTP Authentification