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  

URLConnection:
  1. URLConnection
  2. URLConnection: connect() throws IOException
  3. URLConnection: getContentEncoding()
  4. URLConnection: getExpiration()
  5. URLConnection: getHeaderFields()
  6. URLConnection: getHeaderField(int n)
  7. URLConnection: getHeaderFieldKey(int n)
  8. URLConnection: getIfModifiedSince()
  9. URLConnection: getLastModified()
  10. URLConnection: getURL()
  11. URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
  12. URLConnection: setDoOutput(boolean dooutput)
  13. URLConnection: setIfModifiedSince(long ifmodifiedsince)
  14. URLConnection: setRequestProperty(String key, String value)
  15. URLConnection: setUseCaches(boolean usecaches)