Java URLConnection get properties

Description

Java URLConnection get properties

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

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

      URL url = new URL("https://www.demo2s.com/");
      URLConnection con = url.openConnection();
      System.out.println("Content-type: " + con.getContentType());
      System.out.println("Content Encoding: " + con.getContentEncoding());
      System.out.println("Content-length: " + con.getContentLength());
      System.out.println("Last-Modified: " + new Date(con.getLastModified()));
      System.out.println("Date: " + new Date(con.getDate()));
      System.out.println("Expires: " + con.getExpiration());
      System.out.println("Connection Timeout: " + con.getConnectTimeout());
   }/*w w w. j a va  2s . c  o  m*/
}



PreviousNext

Related