Java Reference
In-Depth Information
Table 4.3: HTTP Response Header Methods and Functions
Method or Function Name
Purpose
getHeaderField()
Returns the value for the nth header field.
getHeaderField(String name)
Returns the value of the named header field.
getHeaderFieldDate(String
name, long Default)
Returns the value of the named field parsed as date.
getHeaderFieldInt(String name,
int Default)
Returns the value of the named field parsed as a
number.
getHeaderFieldKey(int n)
Returns the key for the nth header field.
getHeaderFields()
Returns an unmodifiable Map of the header fields.
As you can see from the above methods, you can read the headers in a variety of formats.
To read headers as a String , use the getHeaderField function. To read headers as
an int , use the getHeaderFieldInt function. To read the headers as a Date , use
the getHeaderFieldDate function.
MIME Types
One very important HTTP response header is the content type. The content-type
header tells the web browser what type of data the URL is attached to. For example, to deter-
mine the type of content at a URL, you would use the following line of code:
String type = http.getHeaderField("content-type");
This type information is called a Multipurpose Internet Mail Extensions (MIME) type.
The “Mail” in MIME is largely historical. MIME types were originally developed for email at-
tachments, long before there was a World Wide Web (WWW). However, they are now applied
to many different Internet applications, such as web browsers and servers.
A MIME type consists of two identifiers separated by a slash (/). For example
text/html is a mime type that identifies a resource as an HTML document. The first
part of the type, in this case text , identifies the family of the type. The second identifies the
exact type, within that family. Plain text files are also part of the text family, and have the
type text/plain .
Search WWH ::




Custom Search