java.lang.Object | ||||
↳ | java.net.URLConnection | |||
↳ | java.net.HttpURLConnection | |||
↳ | javax.net.ssl.HttpsURLConnection | |||
↳ | sun.net.www.protocol.https.HttpsURLConnectionImpl |
A class to represent an HTTP connection to a remote object. Ideally, this class should subclass and inherit the http handler implementation, but it can't do so because that class have the wrong Java Type. Thus it uses the delegate (aka, the Adapter/Wrapper design pattern) to reuse code from the http handler. Since it would use a delegate to access sun.net.www.protocol.http.HttpURLConnection functionalities, it needs to implement all public methods in it's super class and all the way to Object.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
delegate |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a general request property specified by a
key-value pair.
| |||||||||||
Implements the HTTP protocol handler's "connect" method,
establishing an SSL connection to the server as necessary.
| |||||||||||
Disconnect from the server.
| |||||||||||
Indicates whether some other object is "equal to" this one.
| |||||||||||
Returns the value of the
allowUserInteraction field for
this object. | |||||||||||
Returns the cipher suite in use on this connection.
| |||||||||||
Returns setting for connect timeout.
| |||||||||||
Retrieves the contents of this URL connection.
| |||||||||||
Retrieves the contents of this URL connection.
| |||||||||||
Returns the value of the
content-encoding header field. | |||||||||||
Returns the value of the
content-length header field. | |||||||||||
Returns the value of the
content-type header field. | |||||||||||
Returns the value of the
date header field. | |||||||||||
Returns the default value of a
URLConnection 's
useCaches flag. | |||||||||||
Returns the value of this
URLConnection 's
doInput flag. | |||||||||||
Returns the value of this
URLConnection 's
doOutput flag. | |||||||||||
Returns the error stream if the connection failed
but the server sent useful data nonetheless.
| |||||||||||
Returns the value of the
expires header field. | |||||||||||
Gets a header field by name.
| |||||||||||
Gets a header field by index.
| |||||||||||
Returns the value of the named field parsed as date.
| |||||||||||
Returns the value of the named field parsed as a number.
| |||||||||||
Gets a header field by index.
| |||||||||||
Returns an unmodifiable Map of the header fields.
| |||||||||||
Returns the value of this object's
ifModifiedSince field. | |||||||||||
Returns an input stream that reads from this open connection.
| |||||||||||
Returns the value of this
HttpURLConnection 's
instanceFollowRedirects field. | |||||||||||
Returns the value of the
last-modified header field. | |||||||||||
Returns the certificate chain the client sent to the
server, or null if the client did not authenticate.
| |||||||||||
Returns the principal the client sent to the
server, or null if the client did not authenticate.
| |||||||||||
Returns an output stream that writes to this connection.
| |||||||||||
Returns the principal with which the server authenticated itself,
or throw a SSLPeerUnverifiedException if the server did not authenticate.
| |||||||||||
Returns a permission object representing the permission
necessary to make the connection represented by this
object.
| |||||||||||
Returns setting for read timeout.
| |||||||||||
Get the request method.
| |||||||||||
Returns an unmodifiable Map of general request
properties for this connection.
| |||||||||||
Returns the value of the named general request property for this
connection.
| |||||||||||
Overwrite super class method
| |||||||||||
Gets the HTTP response message, if any, returned along with the
response code from a server.
| |||||||||||
Returns the server's X.509 certificate chain, or null if
the server did not authenticate.
| |||||||||||
Returns the server's certificate chain, or throws
SSLPeerUnverified Exception if
the server did not authenticate.
| |||||||||||
Returns the value of this
URLConnection 's URL
field. | |||||||||||
Returns the value of this
URLConnection 's
useCaches field. | |||||||||||
Returns a hash code value for the object.
| |||||||||||
Set the value of the
allowUserInteraction field of
this URLConnection . | |||||||||||
This method is used to enable streaming of a HTTP request body
without internal buffering, when the content length is not
known in advance.
| |||||||||||
Sets a specified timeout value, in milliseconds, to be used
when opening a communications link to the resource referenced
by this URLConnection.
| |||||||||||
Sets the default value of the
useCaches field to the
specified value. | |||||||||||
Sets the value of the
doInput field for this
URLConnection to the specified value. | |||||||||||
Sets the value of the
doOutput field for this
URLConnection to the specified value. | |||||||||||
This method is used to enable streaming of a HTTP request body
without internal buffering, when the content length is known in
advance.
| |||||||||||
Sets the value of the
ifModifiedSince field of
this URLConnection to the specified value. | |||||||||||
Sets whether HTTP redirects (requests with response code 3xx) should
be automatically followed by this
HttpURLConnection
instance. | |||||||||||
Sets the read timeout to a specified timeout, in
milliseconds.
| |||||||||||
Set the method for the URL request, one of:
| |||||||||||
Sets request property.
| |||||||||||
Sets the value of the
useCaches field of this
URLConnection to the specified value. | |||||||||||
Returns a
String representation of this URL connection. | |||||||||||
Indicates if the connection is going through a proxy.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
| |||||||||||
Used by subclass to access "connected" variable.
| |||||||||||
Used by subclass to access "connected" variable.
| |||||||||||
Obtain a HttpClient object.
| |||||||||||
Create a new HttpClient object, bypassing the cache of
HTTP client objects/connections.
| |||||||||||
Create a new HttpClient object, set up so that it uses
per-instance proxying to the given HTTP proxy.
| |||||||||||
Obtain a HttpClient object, set up so that it uses per-instance
proxying to the given HTTP proxy.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Adds a general request property specified by a key-value pair. This method will not overwrite existing values associated with the same key.
key | the keyword by which the request is known
(e.g., "accept "). |
---|---|
value | the value associated with it. |
Implements the HTTP protocol handler's "connect" method, establishing an SSL connection to the server as necessary.
IOException |
---|
Disconnect from the server.
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
obj | the reference object with which to compare. |
---|
true
if this object is the same as the obj
argument; false
otherwise.Returns the value of the allowUserInteraction
field for
this object.
allowUserInteraction
field for
this object.Returns the cipher suite in use on this connection.
Returns setting for connect timeout.
0 return implies that the option is disabled (i.e., timeout of infinity).
int
that indicates the connect timeout
value in millisecondsRetrieves the contents of this URL connection.
This method first determines the content type of the object by
calling the getContentType
method. If this is
the first time that the application has seen that specific content
type, a content handler for that content type is created:
setContentHandlerFactory
method, the
createContentHandler
method of that instance is called
with the content type as an argument; the result is a content
handler for that content type.
createContentHandler
method returns
null
, then the application loads the class named:
where <contentType> is formed by taking the content-type string, replacing all slash characters with asun.net.www.content.<contentType>
period
('.'), and all other non-alphanumeric characters
with the underscore character '_
'. The alphanumeric
characters are specifically the 26 uppercase ASCII letters
'A
' through 'Z
', the 26 lowercase ASCII
letters 'a
' through 'z
', and the 10 ASCII
digits '0
' through '9
'. If the specified
class does not exist, or is not a subclass of
ContentHandler
, then an
UnknownServiceException
is thrown.
instanceof
operator
should be used to determine the specific kind of object
returned.IOException |
---|
Retrieves the contents of this URL connection.
classes | the Class array
indicating the requested types |
---|
instanceof
operator should be used to
determine the specific kind of object returned.IOException |
---|
Returns the value of the content-encoding
header field.
null
if not known.Returns the value of the content-length
header field.
-1
if the content length is
not known.
Returns the value of the content-type
header field.
null
if not known.Returns the value of the date
header field.
0
if not known. The value returned is the
number of milliseconds since January 1, 1970 GMT.Returns the default value of a URLConnection
's
useCaches
flag.
Ths default is "sticky", being a part of the static state of all URLConnections. This flag applies to the next, and all following URLConnections that are created.
URLConnection
's
useCaches
flag.Returns the value of this URLConnection
's
doInput
flag.
URLConnection
's
doInput
flag.Returns the value of this URLConnection
's
doOutput
flag.
URLConnection
's
doOutput
flag.Returns the error stream if the connection failed but the server sent useful data nonetheless. The typical example is when an HTTP server responds with a 404, which will cause a FileNotFoundException to be thrown in connect, but the server sent an HTML help page with suggestions as to what to do.
This method will not cause a connection to be initiated. If the connection was not connected, or if the server did not have an error while connecting or if the server had an error but no error data was sent, this method will return null. This is the default.
Returns the value of the expires
header field.
Gets a header field by name. Returns null if not known.
name | the name of the header field |
---|
null
if there is no such field in the header.
Gets a header field by index. Returns null if not known.
n | the index of the header field |
---|
n
th header field,
or null
if the value does not exist.Returns the value of the named field parsed as date. The result is the number of milliseconds since January 1, 1970 GMT represented by the named field.
This form of getHeaderField
exists because some
connection types (e.g., http-ng
) have pre-parsed
headers. Classes for that connection type can override this method
and short-circuit the parsing.
name | the name of the header field. |
---|---|
Default | a default value. |
Default
argument is returned if the field is
missing or malformed.
Returns the value of the named field parsed as a number.
This form of getHeaderField
exists because some
connection types (e.g., http-ng
) have pre-parsed
headers. Classes for that connection type can override this method
and short-circuit the parsing.
name | the name of the header field. |
---|---|
Default | the default value. |
Default
value is returned if the field is
missing or malformed.
Gets a header field by index. Returns null if not known.
n | the index of the header field |
---|
n
th header field,
or null
if the key does not exist.
Returns an unmodifiable Map of the header fields. The Map keys are Strings that represent the response-header field names. Each Map value is an unmodifiable List of Strings that represents the corresponding field values.
Returns the value of this object's ifModifiedSince
field.
ifModifiedSince
field.Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.
IOException |
---|
Returns the value of this HttpURLConnection
's
instanceFollowRedirects
field.
HttpURLConnection
's
instanceFollowRedirects
field.Returns the value of the last-modified
header field.
The result is the number of milliseconds since January 1, 1970 GMT.
URLConnection
was last modified, or 0 if not known.Returns the certificate chain the client sent to the server, or null if the client did not authenticate.
Returns the principal the client sent to the server, or null if the client did not authenticate.
Returns an output stream that writes to this connection.
IOException |
---|
Returns the principal with which the server authenticated itself, or throw a SSLPeerUnverifiedException if the server did not authenticate.
SSLPeerUnverifiedException |
---|
Returns a permission object representing the permission
necessary to make the connection represented by this
object. This method returns null if no permission is
required to make the connection. By default, this method
returns java.security.AllPermission
. Subclasses
should override this method and return the permission
that best represents the permission required to make a
a connection to the URL. For example, a URLConnection
representing a file:
URL would return a
java.io.FilePermission
object.
The permission returned may dependent upon the state of the connection. For example, the permission before connecting may be different from that after connecting. For example, an HTTP sever, say foo.com, may redirect the connection to a different host, say bar.com. Before connecting the permission returned by the connection will represent the permission needed to connect to foo.com, while the permission returned after connecting will be to bar.com.
Permissions are generally used for two purposes: to protect caches of objects obtained through URLConnections, and to check the right of a recipient to learn about a particular URL. In the first case, the permission should be obtained after the object has been obtained. For example, in an HTTP connection, this will represent the permission to connect to the host from which the data was ultimately fetched. In the second case, the permission should be obtained and tested before connecting.
IOException |
---|
Returns setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).
int
that indicates the read timeout
value in millisecondsReturns an unmodifiable Map of general request properties for this connection. The Map keys are Strings that represent the request-header field names. Each Map value is a unmodifiable List of Strings that represents the corresponding field values.
IllegalStateException | if already connected |
---|
Returns the value of the named general request property for this connection.
key | the keyword by which the request is known (e.g., "accept"). |
---|
Gets the HTTP response message, if any, returned along with the response code from a server. From responses like:
HTTP/1.0 200 OK HTTP/1.0 404 Not FoundExtracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).
null
IOException |
---|
Returns the server's X.509 certificate chain, or null if the server did not authenticate. NOTE: This method is not necessary for the version of this class implementing javax.net.ssl.HttpsURLConnection, but provided for compatibility with the com.sun.net.ssl.HttpsURLConnection version.
Returns the server's certificate chain, or throws SSLPeerUnverified Exception if the server did not authenticate.
SSLPeerUnverifiedException |
---|
Returns the value of this URLConnection
's URL
field.
URLConnection
's URL
field.Returns the value of this URLConnection
's
useCaches
field.
URLConnection
's
useCaches
field.Returns a hash code value for the object. This method is
supported for the benefit of hashtables such as those provided by
java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hashtables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
Set the value of the allowUserInteraction
field of
this URLConnection
.
allowuserinteraction | the new value. |
---|
This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance. In this mode, chunked transfer encoding is used to send the request body. Note, not all HTTP servers support this mode.
When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
chunklen | The number of bytes to write in each chunk. If chunklen is less than or equal to zero, a default value will be used. |
---|
Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.
Some non-standard implmentation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().
timeout | an int that specifies the connect
timeout value in milliseconds |
---|
Sets the default value of the useCaches
field to the
specified value.
defaultusecaches | the new value. |
---|
Sets the value of the doInput
field for this
URLConnection
to the specified value.
A URL connection can be used for input and/or output. Set the DoInput flag to true if you intend to use the URL connection for input, false if not. The default is true.
doinput | the new value. |
---|
Sets the value of the doOutput
field for this
URLConnection
to the specified value.
A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.
dooutput | the new value. |
---|
This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.
An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.
When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
contentLength | The number of bytes which will be written to the OutputStream. |
---|
Sets the value of the ifModifiedSince
field of
this URLConnection
to the specified value.
ifmodifiedsince | the new value. |
---|
Sets whether HTTP redirects (requests with response code 3xx) should
be automatically followed by this HttpURLConnection
instance.
The default value comes from followRedirects, which defaults to true.
shouldFollow | a boolean indicating
whether or not to follow HTTP redirects. |
---|
Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.
Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().
timeout | an int that specifies the timeout
value to be used in milliseconds |
---|
Set the method for the URL request, one of:
method | the HTTP method |
---|
ProtocolException |
---|
Sets request property. If a property with the key already exists, overwrite its value with the new value.
key | the keyword by which the request is known
(e.g., "accept "). |
---|---|
value | the value to be set |
Sets the value of the useCaches
field of this
URLConnection
to the specified value.
Some protocols do caching of documents. Occasionally, it is important to be able to "tunnel through" and ignore the caches (e.g., the "reload" button in a browser). If the UseCaches flag on a connection is true, the connection is allowed to use whatever caches it can. If false, caches are to be ignored. The default value comes from DefaultUseCaches, which defaults to true.
usecaches | a boolean indicating whether
or not to allow caching |
---|
Returns a String
representation of this URL connection.
URLConnection
.
Indicates if the connection is going through a proxy.
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.
The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
Throwable |
---|
Used by subclass to access "connected" variable. Since we are delegating the actual implementation to "delegate", we need to delegate the access of "connected" as well.
Used by subclass to access "connected" variable. Since we are delegating the actual implementation to "delegate", we need to delegate the access of "connected" as well.
Obtain a HttpClient object. Use the cached copy if specified.
url | the URL being accessed |
---|---|
useCache | whether the cached connection should be used if present |
IOException |
---|
Create a new HttpClient object, bypassing the cache of HTTP client objects/connections.
url | the URL being accessed |
---|
IOException |
---|
Create a new HttpClient object, set up so that it uses per-instance proxying to the given HTTP proxy. This bypasses the cache of HTTP client objects/connections.
url | the URL being accessed |
---|---|
proxyHost | the proxy host to use |
proxyPort | the proxy port to use |
IOException |
---|
Obtain a HttpClient object, set up so that it uses per-instance proxying to the given HTTP proxy. Use the cached copy of HTTP client objects/connections if specified.
url | the URL being accessed |
---|---|
proxyHost | the proxy host to use |
proxyPort | the proxy port to use |
useCache | whether the cached connection should be used if present |
IOException |
---|