FileDocCategorySizeDatePackage
GetURLInfo.javaAPI DocExample2228Sat Jan 24 10:44:26 GMT 2004je3.net

GetURLInfo

public class GetURLInfo extends Object
A class that displays information about a URL.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Create a URL, call printinfo() to display information about it.

        try { printinfo(new URL(args[0])); }
        catch (Exception e) {
            System.err.println(e);
            System.err.println("Usage: java GetURLInfo <url>");
        }
    
public static voidprintinfo(java.net.URL url)
Use the URLConnection class to get info about the URL

        URLConnection c = url.openConnection();  // Get URLConnection from URL
        c.connect();                             // Open a connection to URL
	
        // Display some information about the URL contents
        System.out.println("  Content Type: " + c.getContentType());
        System.out.println("  Content Encoding: " + c.getContentEncoding());
        System.out.println("  Content Length: " + c.getContentLength());
        System.out.println("  Date: " + new Date(c.getDate()));
        System.out.println("  Last Modified: " +new Date(c.getLastModified()));
        System.out.println("  Expiration: " + new Date(c.getExpiration()));
	
        // If it is an HTTP connection, display some additional information.
        if (c instanceof HttpURLConnection) {
            HttpURLConnection h = (HttpURLConnection) c;
            System.out.println("  Request Method: " + h.getRequestMethod());
            System.out.println("  Response Message: " +h.getResponseMessage());
            System.out.println("  Response Code: " + h.getResponseCode());
        }