public abstract class URLConnection extends Object
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. |
openConnection
method on a URL.
connect
method.
The setup parameters are modified using the following methods:
setAllowUserInteraction
setDoInput
setDoOutput
setIfModifiedSince
setUseCaches
and the general request properties are modified using the method:
setRequestProperty
Default values for the AllowUserInteraction
and
UseCaches
parameters can be set using the methods
setDefaultAllowUserInteraction
and
setDefaultUseCaches
.
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:
getContent
getHeaderField
getInputStream
getOutputStream
Certain header fields are accessed frequently. The methods:
getContentEncoding
getContentLength
getContentType
getDate
getExpiration
getLastModifed
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 getContent
,
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:
Note abouthttp://www.ietf.org/rfc/rfc2616.txt
fileNameMap
: In versions prior to JDK 1.1.6,
field fileNameMap
of URLConnection
was public.
In JDK 1.1.6 and later, fileNameMap
is private; accessor
and mutator methods getFileNameMap
and
setFileNameMap
are added
to access it. This change is also described on the
Compatibility page.
Invoking the close() methods on the InputStream or OutputStream of an
URLConnection after a request may free network resources associated with this
instance, unless particular protocol specifications specify different behaviours
for it.URL.openConnection()
,
connect()
,
getContent()
,
getContentEncoding()
,
getContentLength()
,
getContentType()
,
getDate()
,
getExpiration()
,
getHeaderField(int)
,
getHeaderField(java.lang.String)
,
getInputStream()
,
getLastModified()
,
getOutputStream()
,
setAllowUserInteraction(boolean)
,
setDefaultUseCaches(boolean)
,
setDoInput(boolean)
,
setDoOutput(boolean)
,
setIfModifiedSince(long)
,
setRequestProperty(java.lang.String, java.lang.String)
,
setUseCaches(boolean)
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowUserInteraction
If
true , this URL is being examined in
a context in which it makes sense to allow user interactions such
as popping up an authentication dialog. |
protected boolean |
connected
If
false , this connection object has not created a
communications link to the specified URL. |
protected boolean |
doInput
This variable is set by the
setDoInput method. |
protected boolean |
doOutput
This variable is set by the
setDoOutput method. |
protected long |
ifModifiedSince
Some protocols support skipping the fetching of the object unless
the object has been modified more recently than a certain time.
|
protected URL |
|