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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
GetHTTPHeader 
 

In this section, you will learn how to get content-length, content- type, and last-modify date of a file. Here we provide a complete example that uses getHeaderFieldKey() method. Firstly create a class GetHTTPHeader and initialize a class URLConnection. T

 

GetHTTPHeader

                         

In this section, you will learn how to get content-length, content- type, and last-modify date of a file. Here we provide a complete example that uses getHeaderFieldKey() method. Firstly create a class GetHTTPHeader and initialize a class URLConnection. Then we call openConnection() method. After that we use the try and catch block to know whether the code is working correctly or not. 

This is the method returns the key for the
nth header field. The HTTP server returns the status line. In this case, getHeaderField() method returns the status line, but getHeaderFieldKey() method returns null.


Here is the code:

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

public class GetHTTPHeader{
  public static void main (String[] args) throws IOException {
    try {
      URL url = new URL
(
"file:///C:/Documents%20and%20Settings/comp23/Desktop/AnimationLine.html");
      System.out.println(url);
      URLConnection con = url.openConnection();
      for (int i=0; i< 10; i++) {
        String name = con.getHeaderFieldKey(i);
        String value = con.getHeaderField(i);
        if (name == null && value == null){
          break;         
        }
        else{
          System.out.println(name + "=" + value);
        }
      }
    }
    catch (Exception e) {}
  }
}


Here is the code of this program:

C:\rose>java GetHTTPHeader
file:/C:/Documents%20and%20Settings/comp23/Desktop/AnimationLine.html
content-length=110
last-modified=Fri, 15 Jun 2007 12:02:17 GMT

C:\rose>

 

Output of this program

 

                         

» 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.