- java.lang.Object
-
- java.net.URLConnection
-
- java.net.HttpURLConnection
-
- Direct Known Subclasses:
HttpsURLConnection
public abstract class HttpURLConnection extends URLConnection
A URLConnection with support for HTTP-specific features. See the spec for details.Each HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances. Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time.
The HTTP protocol handler has a few settings that can be accessed through System Properties. This covers Proxy settings as well as various other settings.
Security permissions
If a security manager is installed, and if a method is called which results in an attempt to open a connection, the caller must possess either:
- a "connect"
SocketPermissionto the host/port combination of the destination URL or - a
URLPermissionthat permits this request.
If automatic redirection is enabled, and this request is redirected to another destination, then the caller must also have permission to connect to the redirected host/URL.
- Since:
- 1.1
- See Also:
disconnect()
-
-
Field Summary
Fields Modifier and Type Field Description protected intchunkLengthThe chunk-length when using chunked encoding streaming mode for output.protected intfixedContentLengthThe fixed content-length when using fixed-length streaming mode.protected longfixedContentLengthLongThe fixed content-length when using fixed-length streaming mode.static intHTTP_ACCEPTEDHTTP Status-Code 202: Accepted.static intHTTP_BAD_GATEWAYHTTP Status-Code 502: Bad Gateway.static intHTTP_BAD_METHODHTTP Status-Code 405: Method Not Allowed.static intHTTP_BAD_REQUESTHTTP Status-Code 400: Bad Request.static intHTTP_CLIENT_TIMEOUTHTTP Status-Code 408: Request Time-Out.static intHTTP_CONFLICTHTTP Status-Code 409: Conflict.static intHTTP_CREATEDHTTP Status-Code 201: Created.static intHTTP_ENTITY_TOO_LARGEHTTP Status-Code 413: Request Entity Too Large.static intHTTP_FORBIDDENHTTP Status-Code 403: Forbidden.static intHTTP_GATEWAY_TIMEOUTHTTP Status-Code 504: Gateway Timeout.static intHTTP_GONEHTTP Status-Code 410: Gone.static intHTTP_INTERNAL_ERRORHTTP Status-Code 500: Internal Server Error.static intHTTP_LENGTH_REQUIREDHTTP Status-Code 411: Length Required.static intHTTP_MOVED_PERMHTTP Status-Code 301: Moved Permanently.static intHTTP_MOVED_TEMPHTTP Status-Code 302: Temporary Redirect.static intHTTP_MULT_CHOICEHTTP Status-Code 300: Multiple Choices.static intHTTP_NO_CONTENTHTTP Status-Code 204: No Content.static intHTTP_NOT_ACCEPTABLEHTTP Status-Code 406: Not Acceptable.static intHTTP_NOT_AUTHORITATIVEHTTP Status-Code 203: Non-Authoritative Information.static intHTTP_NOT_FOUNDHTTP Status-Code 404: Not Found.static intHTTP_NOT_IMPLEMENTEDHTTP Status-Code 501: Not Implemented.static intHTTP_NOT_MODIFIEDHTTP Status-Code 304: Not Modified.static intHTTP_OKHTTP Status-Code 200: OK.static intHTTP_PARTIALHTTP Status-Code 206: Partial Content.static intHTTP_PAYMENT_REQUIREDHTTP Status-Code 402: Payment Required.static intHTTP_PRECON_FAILEDHTTP Status-Code 412: Precondition Failed.static intHTTP_PROXY_AUTHHTTP Status-Code 407: Proxy Authentication Required.static intHTTP_REQ_TOO_LONGHTTP Status-Code 414: Request-URI Too Large.static intHTTP_RESETHTTP Status-Code 205: Reset Content.static intHTTP_SEE_OTHERHTTP Status-Code 303: See Other.static intHTTP_SERVER_ERRORDeprecated.it is misplaced and shouldn't have existed.static intHTTP_UNAUTHORIZEDHTTP Status-Code 401: Unauthorized.static intHTTP_UNAVAILABLEHTTP Status-Code 503: Service Unavailable.static intHTTP_UNSUPPORTED_TYPEHTTP Status-Code 415: Unsupported Media Type.static intHTTP_USE_PROXYHTTP Status-Code 305: Use Proxy.static intHTTP_VERSIONHTTP Status-Code 505: HTTP Version Not Supported.protected booleaninstanceFollowRedirectsIftrue, the protocol will automatically follow redirects.protected StringmethodThe HTTP method (GET,POST,PUT,etc.).protected intresponseCodeAnintrepresenting the three digit HTTP Status-Code.protected StringresponseMessageThe HTTP response message.-
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpURLConnection(URL u)Constructor for the HttpURLConnection.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voiddisconnect()Indicates that other requests to the server are unlikely in the near future.InputStreamgetErrorStream()Returns the error stream if the connection failed but the server sent useful data nonetheless.static booleangetFollowRedirects()Returns abooleanindicating whether or not HTTP redirects (3xx) should be automatically followed.StringgetHeaderField(int n)Returns the value for thenth header field.longgetHeaderFieldDate(String name, long Default)Returns the value of the named field parsed as date.StringgetHeaderFieldKey(int n)Returns the key for thenth header field.booleangetInstanceFollowRedirects()Returns the value of thisHttpURLConnection'sinstanceFollowRedirectsfield.PermissiongetPermission()Returns aSocketPermissionobject representing the permission necessary to connect to the destination host and port.StringgetRequestMethod()Get the request method.intgetResponseCode()Gets the status code from an HTTP response message.StringgetResponseMessage()Gets the HTTP response message, if any, returned along with the response code from a server.voidsetAuthenticator(Authenticator auth)Supplies anAuthenticatorto be used when authentication is requested through the HTTP protocol for thisHttpURLConnection.voidsetChunkedStreamingMode(int chunklen)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance.voidsetFixedLengthStreamingMode(int contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.voidsetFixedLengthStreamingMode(long contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.static voidsetFollowRedirects(boolean set)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class.voidsetInstanceFollowRedirects(boolean followRedirects)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by thisHttpURLConnectioninstance.voidsetRequestMethod(String method)Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions.abstract booleanusingProxy()Indicates if the connection is going through a proxy.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class java.net.URLConnection
addRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches,
-
-