Return the MIME Header

In this section you will learn about the method to retrieve the MIME header.

Return the MIME Header

In this section you will learn about the method to retrieve the MIME header.

Return the MIME Header

Return the MIME Header

     

In this section you will learn about the method to retrieve the MIME header. MIME is stands for Multipurpose Internet Mail Extensions which is an Internet Standard that extends the format of e-mail to support. A container for MimeHeader objects, which represent the MIME headers that is present in a MIME part of data. Here we provide an example in which we create a class named getMIMEHeader and create an object of URL and pass the user. After that we call a method openConnection() which pass a URLConnection object which represents a connection to the remote object of the URL. After establish a connection we use getContentType() which display the value of the content-type header field e.g. the resource that the URL references, or null if not known. After that we use getContentEncoding() that returns the value of the content-encoding header field, it also refer content encoding of the resource that the URL references, or null if not known. After that we use the getDate() which display expiration date of the resource that this URL references, or 0 if not known. Then we use getLastModified(), it will display the value of the last-modified header field. The getExpiration() method returns the value of the expires header field all the result are the number of milliseconds since January 1, 1970 GMT. The last method getContentLength() used in the program returns the value of the content-length of the header field. 

Here is the Output of the Example :

import java.net.*;
import java.io.IOException;

public class getMIMEHeader {
  public static void main(String args[]) {
  for (int i=0; i < args.length; i++) {
  try {
  URL u = new URL(args[0]);
  URLConnection uc = u.openConnection();
  System.out.println("Content-type: " + uc.getContentType());
  System.out.println("Content-encoding: " + uc.getContentEncoding());
  System.out.println("Date: " new java.util.Date(uc.getDate()));
  System.out.println("Last modified: " new java.util.Date(uc.getLastModified()));
  System.out.println("Expiration date: " new java.util.Date(uc.getExpiration()));
  System.out.println("Content-length: " + uc.getContentLength());
  }  // end try
  catch (MalformedURLException e) {
  System.err.println(args[i" is not a URL I understand");
  }
  catch (IOException e) {
  System.err.println(e);
  }
  System.out.println();
  }  // end for
  }  // end main
}  // end getMIMEHeader

Here is the Output of the Example :

C:\roseindia>javac getMIMEHeader.java

C:\roseindia>java getMIMEHeader http://roseindia.net
Content-type: null
Content-encoding: null
Date: Thu Jan 01 05:30:00 GMT+05:30 1970
Last modified: Thu Jan 01 05:30:00 GMT+05:30 1970
Expiration date: Thu Jan 01 05:30:00 GMT+05:30 1970
Content-length: -1

Download of this example.