img
String getHeaderField(int idx)
Returns the value of the header field at index idx.
(Header field indexes begin at 0.) Returns null if the
value of idx exceeds the number of fields.
String getHeaderField(String fieldName)
Returns the value of header field whose name is
specified by fieldName. Returns null if the specified
name is not found.
String getHeaderFieldKey(int idx)
Returns the header field key at index idx. (Header
field indexes begin at 0.) Returns null if the value
of idx exceeds the number of fields.
Map<String, List<String>>
Returns a map that contains all of the header fields
getHeaderFields( )
and values.
long getLastModified( )
Returns the time and date, represented in terms
of milliseconds since Januar y 1, 1970 GMT, of the
last modification of the resource. Zero is returned
if the last-modified date is unavailable.
InputStream getInputStream( )
Returns an InputStream that is linked to the
throws IOException
resource. This stream can be used to obtain
the content of the resource.
Notice that URLConnection defines several methods that handle header information. A
header consists of pairs of keys and values represented as strings. By using getHeaderField( ),
you can obtain the value associated with a header key. By calling getHeaderFields( ), you
can obtain a map that contains all of the headers. Several standard header fields are available
directly through methods such as getDate( ) and getContentType( ).
The following example creates a URLConnection using the openConnection( ) method
of a URL object and then uses it to examine the document's properties and content:
// Demonstrate URLConnection.
import java.net.*;
import java.io.*;
import java.util.Date;
class UCDemo
{
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http://www.internic.net");
URLConnection hpCon = hp.openConnection();
// get date
long d = hpCon.getDate();
if(d==0)
System.out.println("No date information.");
else
System.out.println("Date: " + new Date(d));
// get content type
System.out.println("Content-Type: " + hpCon.getContentType());
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home