URLConnection
URLConnection is a class for accessing the attributes of a remote resource. You can use URLConnection to inspect the properties of the remote object.
URLConnection defines several useful methods:
int getContentLength( )
- Returns the size in bytes of the content associated with the resource. If the length is unavailable, -1 is returned.
String getContentType( )
- Returns the type of content found in the resource. This is the value of the content-type header field. Returns null if the content type is not available.
long getDate( )
- Returns the time and date of the response represented in terms of milliseconds since January 1, 1970 GMT.
long getExpiration( )
- Returns the expiration time and date of the resource represented in terms of milliseconds since January 1, 1970 GMT. Zero is returned if the expiration date is unavailable.
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>> getHeaderFields( )
- Returns a map that contains all of the header fields and values.
long getLastModified( )
- Returns the time and date, represented in terms of milliseconds since January 1, 1970 GMT, of the last modification of the resource. Zero is returned if the last-modified date is unavailable.
InputStream getInputStream( ) throws IOException
- Returns an InputStream that is linked to the resource. This stream can be used to obtain the content of the resource.
Home
Java Book
Networking
Java Book
Networking
URLConnection:
- URLConnection
- URLConnection: connect() throws IOException
- URLConnection: getContentEncoding()
- URLConnection: getExpiration()
- URLConnection: getHeaderFields()
- URLConnection: getHeaderField(int n)
- URLConnection: getHeaderFieldKey(int n)
- URLConnection: getIfModifiedSince()
- URLConnection: getLastModified()
- URLConnection: getURL()
- URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
- URLConnection: setDoOutput(boolean dooutput)
- URLConnection: setIfModifiedSince(long ifmodifiedsince)
- URLConnection: setRequestProperty(String key, String value)
- URLConnection: setUseCaches(boolean usecaches)