java.lang.Object | +----java.net.URLConnection
public abstract class URLConnection
extends Object
The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. In general, creating a connection to a URL is a multistep process:
openConnection() | connect() |
---|---|
Manipulate parameters that affect the connection to the remote resource. | Interact with the resource; query header fields and contents. |
The setup parameters are modified using the following methods:
and the general request properties are modified using the method:
Default values for the AllowUserInteraction and UseCaches parameters can be set using the methods setDefaultAllowUserInteraction and setDefaultUseCaches. Default values for general request properties can be set using the setDefaultRequestProperty method.
Each of the above set methods has a corresponding get method to retrieve the value of the parameter or general request property. The specific parameters and general request properties that are applicable are protocol specific.
The following methods are used to access the header fields and the contents after the connection is made to the remote object:
Certain header fields are accessed frequently. The methods:
provide convenient access to these fields. The getContentType method is used by the getContent method to determine the type of the remote object; subclasses may find it convenient to override the getContentType method.
In the common case, all of the pre-connection parameters and general request properties can be ignored: the pre-connection parameters and request properties default to sensible values. For most clients of this interface, there are only two interesting methods: getInputStream and getObject, which are mirrored in the URL class by convenience methods.
More information on the request properties and header fields of an http connection can be found at: