HttpURLConnection (Java SE 26 & JDK 26)
- Direct Known Subclasses:
HttpsURLConnection
-
Field Summary
Fields
protected intThe chunk-length when using chunked encoding streaming mode for output.
protected intThe fixed content-length when using fixed-length streaming mode.
protected longThe fixed content-length when using fixed-length streaming mode.
static final intHTTP Status-Code 202: Accepted.
static final intHTTP Status-Code 502: Bad Gateway.
static final intHTTP Status-Code 405: Method Not Allowed.
static final intHTTP Status-Code 400: Bad Request.
static final intHTTP Status-Code 408: Request Time-Out.
static final intHTTP Status-Code 409: Conflict.
static final intHTTP Status-Code 201: Created.
static final intHTTP Status-Code 413: Request Entity Too Large.
static final intHTTP Status-Code 403: Forbidden.
static final intHTTP Status-Code 504: Gateway Timeout.
static final intHTTP Status-Code 410: Gone.
static final intHTTP Status-Code 500: Internal Server Error.
static final intHTTP Status-Code 411: Length Required.
static final intHTTP Status-Code 301: Moved Permanently.
static final intHTTP Status-Code 302: Temporary Redirect.
static final intHTTP Status-Code 300: Multiple Choices.
static final intHTTP Status-Code 204: No Content.
static final intHTTP Status-Code 406: Not Acceptable.
static final intHTTP Status-Code 203: Non-Authoritative Information.
static final intHTTP Status-Code 404: Not Found.
static final intHTTP Status-Code 501: Not Implemented.
static final intHTTP Status-Code 304: Not Modified.
static final intHTTP Status-Code 200: OK.
static final intHTTP Status-Code 206: Partial Content.
static final intHTTP Status-Code 402: Payment Required.
static final intHTTP Status-Code 412: Precondition Failed.
static final intHTTP Status-Code 407: Proxy Authentication Required.
static final intHTTP Status-Code 414: Request-URI Too Large.
static final intHTTP Status-Code 205: Reset Content.
static final intHTTP Status-Code 303: See Other.
static final intstatic final intHTTP Status-Code 401: Unauthorized.
static final intHTTP Status-Code 503: Service Unavailable.
static final intHTTP Status-Code 415: Unsupported Media Type.
static final intHTTP Status-Code 305: Use Proxy.
static final intHTTP Status-Code 505: HTTP Version Not Supported.
protected booleanIf
true, the protocol will automatically follow redirects.The HTTP method (GET,POST,PUT,etc.).
protected intAn
intrepresenting the three digit HTTP Status-Code.The HTTP response message.
Fields declared in class URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCachesprotected booleanIf
true, thisURLis being examined in a context in which it makes sense to allow user interactions such as popping up an authentication dialog.protected booleanIf
false, this connection object has not created a communications link to the specified URL.protected booleanThis variable is set by the
setDoInputmethod.protected booleanThis variable is set by the
setDoOutputmethod.protected longSome protocols support skipping the fetching of the object unless the object has been modified more recently than a certain time.
protected URLThe URL represents the remote object on the World Wide Web to which this connection is opened.
protected booleanIf
true, the protocol is allowed to use caching whenever it can. -
Constructor Summary
Constructors
protectedConstructor for the HttpURLConnection.
-
Method Summary
abstract voidIndicates that other requests to the server are unlikely in the near future.
Returns the error stream if the connection failed but the server sent useful data nonetheless.
static booleanReturns a
booleanindicating whether or not HTTP redirects (3xx) should be automatically followed.getHeaderField(int n) Returns the value for the
nth header field.getHeaderFieldKey(int n) Returns the key for the
nth header field.booleanReturns the value of this
HttpURLConnection'sinstanceFollowRedirectsfield.Deprecated, for removal: This API element is subject to removal in a future version.
intGets the status code from an HTTP response message.
Gets the HTTP response message, if any, returned along with the response code from a server.
voidSupplies an
Authenticatorto 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 this
HttpURLConnectioninstance.voidSet the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions.
abstract booleanIndicates if the connection is going through a proxy.
Methods declared in class URLConnection
addRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toStringvoidAdds a general request property specified by a key-value pair.
abstract voidOpens a communications link to the resource referenced by this URL, if such a connection has not already been established.
booleanReturns the value of the
allowUserInteractionfield for this object.intReturns setting for connect timeout.
Retrieves the contents of this URL connection.
Retrieves the contents of this URL connection.
Returns the value of the
content-encodingheader field.intReturns the value of the
content-lengthheader field.longReturns the value of the
content-lengthheader field as a long.Returns the value of the
content-typeheader field.longReturns the value of the
dateheader field.static booleanReturns the default value of the
allowUserInteractionfield.booleanReturns the default value of a
URLConnection'suseCachesflag.static booleanReturns the default value of the
useCachesflag for the given protocol.booleanReturns the value of this
URLConnection'sdoInputflag.booleanReturns the value of this
URLConnection'sdoOutputflag.longReturns the value of the
expiresheader field.Loads filename map (a mimetable) from a data file.
Returns the value of the named header field.
longReturns the value of the named field parsed as date.
intReturns the value of the named field parsed as a number.
longReturns the value of the named field parsed as a number.
Returns an unmodifiable Map of the header fields.
longReturns the value of this object's
ifModifiedSincefield.Returns an input stream that reads from this open connection.
longReturns the value of the
last-modifiedheader field.Returns an output stream that writes to this connection.
intReturns setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).
Returns an unmodifiable Map of general request properties for this connection.
Returns the value of the named general request property for this connection.
Returns the value of this
URLConnection'sURLfield.booleanReturns the value of this
URLConnection'suseCachesfield.Tries to determine the content type of an object, based on the specified "file" component of a URL.
Tries to determine the type of an input stream based on the characters at the beginning of the input stream.
voidSet the value of the
allowUserInteractionfield of thisURLConnection.voidSets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.
static voidSets the
ContentHandlerFactoryof an application.static voidSets the default value of the
allowUserInteractionfield for all futureURLConnectionobjects to the specified value.static voidvoidSets the default value of the
useCachesfield to the specified value.static voidSets the default value of the
useCachesfield for the named protocol to the given value.voidSets the value of the
doInputfield for thisURLConnectionto the specified value.voidSets the value of the
doOutputfield for thisURLConnectionto the specified value.static voidvoidSets the value of the
ifModifiedSincefield of thisURLConnectionto the specified value.voidSets the read timeout to a specified timeout, in milliseconds.
voidSets the general request property.
voidSets the value of the
useCachesfield of thisURLConnectionto the specified value.Returns a
Stringrepresentation of this URL connection.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitCreates and returns a copy of this object.
booleanIndicates whether some other object is "equal to" this one.
protected voidDeprecated, for removal: This API element is subject to removal in a future version.
Returns the runtime class of this
Object.intReturns a hash code value for this object.
final voidWakes up a single thread that is waiting on this object's monitor.
final voidWakes up all threads that are waiting on this object's monitor.
final voidCauses the current thread to wait until it is awakened, typically by being notified or interrupted.
final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Field Details
-
method
-
chunkLength
-
fixedContentLength
-
fixedContentLengthLong
-
responseCode
-
responseMessage
-
instanceFollowRedirects
-
HTTP_OK
-
HTTP_CREATED
-
HTTP_ACCEPTED
-
HTTP_NOT_AUTHORITATIVE
-
HTTP_NO_CONTENT
-
HTTP_RESET
-
HTTP_PARTIAL
-
HTTP_MULT_CHOICE
-
HTTP_MOVED_PERM
-
HTTP_MOVED_TEMP
-
HTTP_SEE_OTHER
-
HTTP_NOT_MODIFIED
-
HTTP_USE_PROXY
-
HTTP_BAD_REQUEST
-
HTTP_UNAUTHORIZED
-
HTTP_PAYMENT_REQUIRED
-
HTTP_FORBIDDEN
-
HTTP_NOT_FOUND
-
HTTP_BAD_METHOD
-
HTTP_NOT_ACCEPTABLE
-
HTTP_PROXY_AUTH
-
HTTP_CLIENT_TIMEOUT
-
HTTP_CONFLICT
-
HTTP_GONE
-
HTTP_LENGTH_REQUIRED
-
HTTP_PRECON_FAILED
-
HTTP_ENTITY_TOO_LARGE
-
HTTP_REQ_TOO_LONG
-
HTTP_UNSUPPORTED_TYPE
-
HTTP_SERVER_ERROR
-
HTTP_INTERNAL_ERROR
-
HTTP_NOT_IMPLEMENTED
-
HTTP_BAD_GATEWAY
-
HTTP_UNAVAILABLE
-
HTTP_GATEWAY_TIMEOUT
-
HTTP_VERSION
-
-
Constructor Details
-
HttpURLConnection
-
-
Method Details
-
setAuthenticator
-
setFixedLengthStreamingMode
-
setFixedLengthStreamingMode
-
setChunkedStreamingMode
-
setFollowRedirects
-
getFollowRedirects
-
setInstanceFollowRedirects
-
getInstanceFollowRedirects
-
setRequestMethod
-
getRequestMethod
-
getResponseCode
-
getResponseMessage
-
disconnect
-
usingProxy
-
getPermission
-
getErrorStream
-