Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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. 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.

 

                         

» View all related tutorials
Related Tags: c com forms server orm form network socket io sed request return opera ai for work wait to base pos

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.