|
|||||||||
| Home >> All >> java >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.net
Class HttpURLConnection

java.lang.Objectjava.net.URLConnection
java.net.HttpURLConnection
- public abstract class HttpURLConnection
- extends URLConnection
This class provides a common abstract implementation for those URL connection classes that will connect using the HTTP protocol. In addition to the functionality provided by the URLConnection class, it defines constants for HTTP return code values and methods for setting the HTTP request method and determining whether or not to follow redirects.
- Since:
- 1.1
| Field Summary | |
private static boolean |
followRedirects
Flag to indicate whether or not redirects should be automatically followed by default. |
private boolean |
gotResponseVals
Whether we already got a valid response code for this connection. |
static int |
HTTP_ACCEPTED
The request has been accepted for processing but has not completed. |
static int |
HTTP_BAD_GATEWAY
The proxy encountered a bad response from the server it was proxy-ing for |
static int |
HTTP_BAD_METHOD
The specified request method is not allowed for this resource. |
static int |
HTTP_BAD_REQUEST
The request was misformed or could not be understood. |
static int |
HTTP_CLIENT_TIMEOUT
The request timed out. |
static int |
HTTP_CONFLICT
There is a conflict between the current state of the resource and the requested action. |
(package private) static int |
HTTP_CONTINUE
Indicates that the client may continue with its request. |
static int |
HTTP_CREATED
The requested resource has been created. |
static int |
HTTP_ENTITY_TOO_LARGE
The request sent was too large for the server to handle. |
static int |
HTTP_FORBIDDEN
There is no permission to access the requested resource. |
static int |
HTTP_GATEWAY_TIMEOUT
The proxy timed out getting a reply from the remote server it was proxy-ing for. |
static int |
HTTP_GONE
The requested resource is no longer available. |
static int |
HTTP_INTERNAL_ERROR
The server encountered an unexpected error (such as a CGI script crash) that prevents the request from being fulfilled. |
static int |
HTTP_LENGTH_REQUIRED
A Content-Length header is required for this request, but was not supplied. |
static int |
HTTP_MOVED_PERM
The resource has been permanently moved to a new location. |
static int |
HTTP_MOVED_TEMP
The resource requested has been temporarily moved to a new location. |
static int |
HTTP_MULT_CHOICE
There is a list of choices available for the requested resource. |
static int |
HTTP_NO_CONTENT
The server performed the request, but there is no data to send back. |
static int |
HTTP_NOT_ACCEPTABLE
Based on the input headers sent, the resource returned in response to the request would not be acceptable to the client. |
static int |
HTTP_NOT_AUTHORITATIVE
The meta-information returned in the header is not the actual data from the original server, but may be from a local or other copy. |
static int |
HTTP_NOT_FOUND
The requested resource was not found. |
static int |
HTTP_NOT_IMPLEMENTED
The server does not support the requested functionality. |
static int |
HTTP_NOT_MODIFIED
The document has not been modified since the criteria specified in a conditional GET. |
static int |
HTTP_OK
Indicates the request succeeded. |
static int |
HTTP_PARTIAL
The server completed the partial GET request for the resource. |
static int |
HTTP_PAYMENT_REQUIRED
Code reserved for future use - I hope way in the future. |
static int |
HTTP_PRECON_FAILED
A client specified pre-condition was not met on the server. |
static int |
HTTP_PROXY_AUTH
The client must authenticate with a proxy prior to attempting this request. |
static int |
HTTP_REQ_TOO_LONG
The name of the resource specified was too long. |
static int |
HTTP_RESET
The server performed the request, but there is no data to sent back, however, the user's display should be "reset" to clear out any form fields entered. |
static int |
HTTP_SEE_OTHER
The response to the request issued is available at another location. |
static int |
HTTP_SERVER_ERROR
Deprecated. |
static int |
HTTP_UNAUTHORIZED
The request made requires user authorization. |
static int |
HTTP_UNAVAILABLE
The HTTP service is not availalble, such as because it is overloaded and does not want additional requests. |
static int |
HTTP_UNSUPPORTED_TYPE
The request is in a format not supported by the requested resource. |
static int |
HTTP_USE_PROXY
The requested resource needs to be accessed through a proxy. |
static int |
HTTP_VERSION
This server does not support the protocol version requested. |
protected boolean |
instanceFollowRedirects
If this instance should follow redirect requests. |
protected java.lang.String |
method
The requested method in use for this connection. |
protected int |
responseCode
The response code received from the server |
protected java.lang.String |
responseMessage
The response message string received from the server. |
private static java.lang.String |
valid_methods
This is a list of valid request methods, separated by "|" characters. |
| Fields inherited from class java.net.URLConnection |
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches |
| Constructor Summary | |
protected |
HttpURLConnection(URL url)
Create an HttpURLConnection for the specified URL |
| Method Summary | |
abstract void |
disconnect()
Closes the connection to the server. |
java.io.InputStream |
getErrorStream()
This method allows the caller to retrieve any data that might have been sent despite the fact that an error occurred. |
static boolean |
getFollowRedirects()
Returns a boolean indicating whether or not HTTP redirects will automatically be followed or not. |
long |
getHeaderFieldDate(java.lang.String key,
long value)
Returns the value of the named field parsed as date |
boolean |
getInstanceFollowRedirects()
Returns the value of this HttpURLConnection's instanceFollowRedirects field |
java.security.Permission |
getPermission()
Returns a permission object representing the permission necessary to make the connection represented by this object |
java.lang.String |
getRequestMethod()
The request method currently in use for this connection. |
int |
getResponseCode()
Gets the status code from an HTTP response message, or -1 if the response code could not be determined. |
java.lang.String |
getResponseMessage()
Gets the HTTP response message, if any, returned along with the response code from a server. |
private void |
getResponseVals()
|
static void |
setFollowRedirects(boolean set)
Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class. |
void |
setInstanceFollowRedirects(boolean follow)
Sets the value of this HttpURLConnection's instanceFollowRedirects field |
void |
setRequestMethod(java.lang.String method)
Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal |
abstract boolean |
usingProxy()
Returns a boolean indicating whether or not this connection is going through a proxy |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
HTTP_CONTINUE
static final int HTTP_CONTINUE
- Indicates that the client may continue with its request. This value
is specified as part of RFC 2068 but was not included in Sun's JDK, so
beware of using this value
- See Also:
- Constant Field Values
HTTP_OK
public static final int HTTP_OK
- Indicates the request succeeded.
- See Also:
- Constant Field Values
HTTP_CREATED
public static final int HTTP_CREATED
- The requested resource has been created.
- See Also:
- Constant Field Values
HTTP_ACCEPTED
public static final int HTTP_ACCEPTED
- The request has been accepted for processing but has not completed.
There is no guarantee that the requested action will actually ever
be completed succesfully, but everything is ok so far.
- See Also:
- Constant Field Values
HTTP_NOT_AUTHORITATIVE
public static final int HTTP_NOT_AUTHORITATIVE
- The meta-information returned in the header is not the actual data
from the original server, but may be from a local or other copy.
Normally this still indicates a successful completion.
- See Also:
- Constant Field Values
HTTP_NO_CONTENT
public static final int HTTP_NO_CONTENT
- The server performed the request, but there is no data to send
back. This indicates that the user's display should not be changed.
- See Also:
- Constant Field Values
HTTP_RESET
public static final int HTTP_RESET
- The server performed the request, but there is no data to sent back,
however, the user's display should be "reset" to clear out any form
fields entered.
- See Also:
- Constant Field Values
HTTP_PARTIAL
public static final int HTTP_PARTIAL
- The server completed the partial GET request for the resource.
- See Also:
- Constant Field Values
HTTP_MULT_CHOICE
public static final int HTTP_MULT_CHOICE
- There is a list of choices available for the requested resource.
- See Also:
- Constant Field Values
HTTP_MOVED_PERM
public static final int HTTP_MOVED_PERM
- The resource has been permanently moved to a new location.
- See Also:
- Constant Field Values
HTTP_MOVED_TEMP
public static final int HTTP_MOVED_TEMP
- The resource requested has been temporarily moved to a new location.
- See Also:
- Constant Field Values
HTTP_SEE_OTHER
public static final int HTTP_SEE_OTHER
- The response to the request issued is available at another location.
- See Also:
- Constant Field Values
HTTP_NOT_MODIFIED
public static final int HTTP_NOT_MODIFIED
- The document has not been modified since the criteria specified in
a conditional GET.
- See Also:
- Constant Field Values
HTTP_USE_PROXY
public static final int HTTP_USE_PROXY
- The requested resource needs to be accessed through a proxy.
- See Also:
- Constant Field Values
HTTP_BAD_REQUEST
public static final int HTTP_BAD_REQUEST
- The request was misformed or could not be understood.
- See Also:
- Constant Field Values
HTTP_UNAUTHORIZED
public static final int HTTP_UNAUTHORIZED
- The request made requires user authorization. Try again with
a correct authentication header.
- See Also:
- Constant Field Values
HTTP_PAYMENT_REQUIRED
public static final int HTTP_PAYMENT_REQUIRED
- Code reserved for future use - I hope way in the future.
- See Also:
- Constant Field Values
HTTP_FORBIDDEN
public static final int HTTP_FORBIDDEN
- There is no permission to access the requested resource.
- See Also:
- Constant Field Values
HTTP_NOT_FOUND
public static final int HTTP_NOT_FOUND
- The requested resource was not found.
- See Also:
- Constant Field Values
HTTP_BAD_METHOD
public static final int HTTP_BAD_METHOD
- The specified request method is not allowed for this resource.
- See Also:
- Constant Field Values
HTTP_NOT_ACCEPTABLE
public static final int HTTP_NOT_ACCEPTABLE
- Based on the input headers sent, the resource returned in response
to the request would not be acceptable to the client.
- See Also:
- Constant Field Values
HTTP_PROXY_AUTH
public static final int HTTP_PROXY_AUTH
- The client must authenticate with a proxy prior to attempting this
request.
- See Also:
- Constant Field Values
HTTP_CLIENT_TIMEOUT
public static final int HTTP_CLIENT_TIMEOUT
- The request timed out.
- See Also:
- Constant Field Values
HTTP_CONFLICT
public static final int HTTP_CONFLICT
- There is a conflict between the current state of the resource and the
requested action.
- See Also:
- Constant Field Values
HTTP_GONE
public static final int HTTP_GONE
- The requested resource is no longer available. This ususally indicates
a permanent condition.
- See Also:
- Constant Field Values
HTTP_LENGTH_REQUIRED
public static final int HTTP_LENGTH_REQUIRED
- A Content-Length header is required for this request, but was not
supplied.
- See Also:
- Constant Field Values
HTTP_PRECON_FAILED
public static final int HTTP_PRECON_FAILED
- A client specified pre-condition was not met on the server.
- See Also:
- Constant Field Values
HTTP_ENTITY_TOO_LARGE
public static final int HTTP_ENTITY_TOO_LARGE
- The request sent was too large for the server to handle.
- See Also:
- Constant Field Values
HTTP_REQ_TOO_LONG
public static final int HTTP_REQ_TOO_LONG
- The name of the resource specified was too long.
- See Also:
- Constant Field Values
HTTP_UNSUPPORTED_TYPE
public static final int HTTP_UNSUPPORTED_TYPE
- The request is in a format not supported by the requested resource.
- See Also:
- Constant Field Values
HTTP_SERVER_ERROR
public static final int HTTP_SERVER_ERROR
- Deprecated.
- This error code indicates that some sort of server error occurred.
- See Also:
- Constant Field Values
- This error code indicates that some sort of server error occurred.
HTTP_INTERNAL_ERROR
public static final int HTTP_INTERNAL_ERROR
- The server encountered an unexpected error (such as a CGI script crash)
that prevents the request from being fulfilled.
- See Also:
- Constant Field Values
HTTP_NOT_IMPLEMENTED
public static final int HTTP_NOT_IMPLEMENTED
- The server does not support the requested functionality.
- Since:
- 1.3
- See Also:
- Constant Field Values
HTTP_BAD_GATEWAY
public static final int HTTP_BAD_GATEWAY
- The proxy encountered a bad response from the server it was proxy-ing for
- See Also:
- Constant Field Values
HTTP_UNAVAILABLE
public static final int HTTP_UNAVAILABLE
- The HTTP service is not availalble, such as because it is overloaded
and does not want additional requests.
- See Also:
- Constant Field Values
HTTP_GATEWAY_TIMEOUT
public static final int HTTP_GATEWAY_TIMEOUT
- The proxy timed out getting a reply from the remote server it was
proxy-ing for.
- See Also:
- Constant Field Values
HTTP_VERSION
public static final int HTTP_VERSION
- This server does not support the protocol version requested.
- See Also:
- Constant Field Values
followRedirects
private static boolean followRedirects
- Flag to indicate whether or not redirects should be automatically
followed by default.
valid_methods
private static final java.lang.String valid_methods
- This is a list of valid request methods, separated by "|" characters.
- See Also:
- Constant Field Values
method
protected java.lang.String method
- The requested method in use for this connection. Default is GET.
responseCode
protected int responseCode
- The response code received from the server
responseMessage
protected java.lang.String responseMessage
- The response message string received from the server.
instanceFollowRedirects
protected boolean instanceFollowRedirects
- If this instance should follow redirect requests.
gotResponseVals
private boolean gotResponseVals
- Whether we already got a valid response code for this connection.
Used by
getResponseCode()andgetResponseMessage().
| Constructor Detail |
HttpURLConnection
protected HttpURLConnection(URL url)
- Create an HttpURLConnection for the specified URL
| Method Detail |
disconnect
public abstract void disconnect()
- Closes the connection to the server.
usingProxy
public abstract boolean usingProxy()
- Returns a boolean indicating whether or not this connection is going
through a proxy
setFollowRedirects
public static void setFollowRedirects(boolean set)
- Sets whether HTTP redirects (requests with response code 3xx) should be
automatically followed by this class. True by default
getFollowRedirects
public static boolean getFollowRedirects()
- Returns a boolean indicating whether or not HTTP redirects will
automatically be followed or not.
getInstanceFollowRedirects
public boolean getInstanceFollowRedirects()
- Returns the value of this HttpURLConnection's instanceFollowRedirects
field
setInstanceFollowRedirects
public void setInstanceFollowRedirects(boolean follow)
- Sets the value of this HttpURLConnection's instanceFollowRedirects field
setRequestMethod
public void setRequestMethod(java.lang.String method) throws ProtocolException
- Set the method for the URL request, one of:
GET POST HEAD OPTIONS PUT DELETE TRACE are legal
getRequestMethod
public java.lang.String getRequestMethod()
- The request method currently in use for this connection.
getResponseCode
public int getResponseCode()
throws java.io.IOException
- Gets the status code from an HTTP response message, or -1 if
the response code could not be determined.
Note that all valid response codes have class variables
defined for them in this class.
getResponseMessage
public java.lang.String getResponseMessage() throws java.io.IOException
- Gets the HTTP response message, if any, returned along with the
response code from a server. Null if no response message was set
or an error occured while connecting.
getResponseVals
private void getResponseVals()
throws java.io.IOException
getPermission
public java.security.Permission getPermission() throws java.io.IOException
- Returns a permission object representing the permission necessary to make
the connection represented by this object
- Overrides:
getPermissionin classURLConnection
getErrorStream
public java.io.InputStream getErrorStream()
- This method allows the caller to retrieve any data that might have
been sent despite the fact that an error occurred. For example, the
HTML page sent along with a 404 File Not Found error. If the socket
is not connected, or if no error occurred or no data was returned,
this method returns
null.
getHeaderFieldDate
public long getHeaderFieldDate(java.lang.String key, long value)
- Returns the value of the named field parsed as date
- Overrides:
getHeaderFieldDatein classURLConnection
|
|||||||||
| Home >> All >> java >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC