public abstract class HttpURLConnection extends URLConnection
URLConnection
defines methods for managing
HTTP connection according to the description given by RFC 2068.ContentHandler
,
URL
,
URLConnection
,
URLStreamHandler
Modifier and Type | Field and Description |
---|---|
static int |
HTTP_ACCEPTED
If using HTTP fixed-length streaming mode this parameter defines the
fixed length of content.
|
static int |
HTTP_BAD_GATEWAY |
static int |
HTTP_BAD_METHOD |
static int |
HTTP_BAD_REQUEST |
static int |
HTTP_CLIENT_TIMEOUT |
static int |
HTTP_CONFLICT |
static int |
HTTP_CREATED |
static int |
HTTP_ENTITY_TOO_LARGE |
static int |
HTTP_FORBIDDEN |
static int |
HTTP_GATEWAY_TIMEOUT |
static int |
HTTP_GONE |
static int |
HTTP_INTERNAL_ERROR |
static int |
HTTP_LENGTH_REQUIRED |
static int |
HTTP_MOVED_PERM |
static int |
HTTP_MOVED_TEMP |
static int |
HTTP_MULT_CHOICE |
static int |
HTTP_NO_CONTENT |
static int |
HTTP_NOT_ACCEPTABLE |
static int |
HTTP_NOT_AUTHORITATIVE |
static int |
HTTP_NOT_FOUND |
static int |
HTTP_NOT_IMPLEMENTED |
static int |
HTTP_NOT_MODIFIED |
static int |
HTTP_OK |
static int |
HTTP_PARTIAL |
static int |
HTTP_PAYMENT_REQUIRED |
static int |
HTTP_PRECON_FAILED |
static int |
HTTP_PROXY_AUTH |
static int |
HTTP_REQ_TOO_LONG |
static int |
HTTP_RESET |
static int |
HTTP_SEE_OTHER |
static int |
HTTP_SERVER_ERROR |
static int |
HTTP_UNAUTHORIZED |
static int |
HTTP_UNAVAILABLE |
static int |
HTTP_UNSUPPORTED_TYPE |
static int |
HTTP_USE_PROXY |
static int |
HTTP_VERSION |
protected boolean |
instanceFollowRedirects
Flag to define whether the protocol will automatically follow redirects
or not.
|
protected String |
method
The HTTP request method of this
HttpURLConnection . |
protected int |
responseCode
The status code of the response obtained from the HTTP request.
|
protected String |
responseMessage
The HTTP response message which corresponds to the response code.
|
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
Modifier | Constructor and Description |
---|---|
protected |
HttpURLConnection(URL url)
Constructs a new
HttpURLConnection instance pointing to the
resource specified by the url . |
Modifier and Type | Method and Description |
---|---|
abstract void |
disconnect()
Closes the connection to the HTTP server.
|
InputStream |
getErrorStream()
Returns an input stream from the server in the case of an error such as
the requested file has not been found on the remote server.
|
static boolean |
getFollowRedirects()
Returns the value of
followRedirects which indicates if this
connection follows a different URL redirected by the server. |
long |
getHeaderFieldDate(String field,
long defaultValue)
Returns the date value in milliseconds since
01.01.1970, 00:00h
corresponding to the header field field . |
boolean |
getInstanceFollowRedirects()
Returns whether this connection follows redirects.
|
Permission |
getPermission()
Returns the permission object (in this case
SocketPermission )
with the host and the port number as the target name and "resolve, connect" as the action list. |
String |
getRequestMethod()
Returns the request method which will be used to make the request to the
remote HTTP server.
|
int |
getResponseCode()
Returns the response code returned by the remote HTTP server.
|
String |
getResponseMessage()
Returns the response message returned by the remote HTTP server.
|
static void |
setFollowRedirects(boolean auto)
Sets the flag of whether this connection will follow redirects returned
by the remote server.
|
void |
setInstanceFollowRedirects(boolean followRedirects)
Sets whether this connection follows redirects.
|
void |
setRequestMethod(String method)
Sets the request command which will be sent to the remote HTTP server.
|
abstract boolean |
usingProxy()
Returns whether this connection uses a proxy server or not.
|
addRequestProperty, connect, getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setRequestProperty, setUseCaches, toString
protected String method
HttpURLConnection
. The default
value is "GET"
.protected int responseCode
-1
.
protected String responseMessage
protected boolean instanceFollowRedirects
true
.public static final int HTTP_ACCEPTED
-1
that means the
fixed-length streaming mode is disabled.public static final int HTTP_BAD_GATEWAY
public static final int HTTP_BAD_METHOD
public static final int HTTP_BAD_REQUEST
public static final int HTTP_CLIENT_TIMEOUT
public static final int HTTP_CONFLICT
public static final int HTTP_CREATED
public static final int HTTP_ENTITY_TOO_LARGE
public static final int HTTP_FORBIDDEN
public static final int HTTP_GATEWAY_TIMEOUT
public static final int HTTP_GONE
public static final int HTTP_INTERNAL_ERROR
public static final int HTTP_LENGTH_REQUIRED
public static final int HTTP_MOVED_PERM
public static final int HTTP_MOVED_TEMP
public static final int HTTP_MULT_CHOICE
public static final int HTTP_NO_CONTENT
public static final int HTTP_NOT_ACCEPTABLE
public static final int HTTP_NOT_AUTHORITATIVE
public static final int HTTP_NOT_FOUND
public static final int HTTP_NOT_IMPLEMENTED
public static final int HTTP_NOT_MODIFIED
public static final int HTTP_OK
public static final int HTTP_PARTIAL
public static final int HTTP_PAYMENT_REQUIRED
public static final int HTTP_PRECON_FAILED
public static final int HTTP_PROXY_AUTH
public static final int HTTP_REQ_TOO_LONG
public static final int HTTP_RESET
public static final int HTTP_SEE_OTHER
public static final int HTTP_SERVER_ERROR
public static final int HTTP_USE_PROXY
public static final int HTTP_UNAUTHORIZED
public static final int HTTP_UNSUPPORTED_TYPE
public static final int HTTP_UNAVAILABLE
public static final int HTTP_VERSION
protected HttpURLConnection(URL url)
HttpURLConnection
instance pointing to the
resource specified by the url
.url
- the URL of this connection.URL
,
URLConnection
public abstract void disconnect()
public InputStream getErrorStream()
public static boolean getFollowRedirects()
followRedirects
which indicates if this
connection follows a different URL redirected by the server. It is
enabled by default.setFollowRedirects(boolean)
public Permission getPermission() throws IOException
SocketPermission
)
with the host and the port number as the target name and "resolve, connect"
as the action list. If the port number of this URL
instance is lower than 0
the port will be set to 80
.getPermission
in class URLConnection
IOException
- if an IO exception occurs during the creation of the
permission object.public String getRequestMethod()
method
,
setRequestMethod(java.lang.String)
public int getResponseCode() throws IOException
IOException
- if there is an IO error during the retrieval.getResponseMessage()
public String getResponseMessage() throws IOException
null
if no such response exists.IOException
- if there is an error during the retrieval.getResponseCode()
public static void setFollowRedirects(boolean auto)
auto
- the value to enable or disable this option.SecurityManager.checkSetFactory()
public void setRequestMethod(String method) throws ProtocolException
method
- the string representing the method to be used.ProtocolException
- if this is called after connected, or the method is not
supported by this HTTP implementation.getRequestMethod()
,
method
public abstract boolean usingProxy()
true
if this connection passes a proxy server, false
otherwise.public boolean getInstanceFollowRedirects()
true
if this connection follows redirects, false
otherwise.public void setInstanceFollowRedirects(boolean followRedirects)
followRedirects
- true
if this connection will follows redirects, false
otherwise.public long getHeaderFieldDate(String field, long defaultValue)
01.01.1970, 00:00h
corresponding to the header field field
. The defaultValue
will be returned if no such field can be found in the response header.getHeaderFieldDate
in class URLConnection
field
- the header field name.defaultValue
- the default value to use if the specified header field wont be
found.