java.net
Class HttpURLConnection

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.net.URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection 
      extended by java.net.HttpURLConnection

public abstract class HttpURLConnection
extends URLConnection sample code for java.net.URLConnection definition code for java.net.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.

Since:
JDK1.1
See Also:
disconnect() sample code for java.net.HttpURLConnection.disconnect() definition code for java.net.HttpURLConnection.disconnect()

Field Summary
protected  int chunkLength sample code for java.net.HttpURLConnection.chunkLength definition code for java.net.HttpURLConnection.chunkLength
          The chunk-length when using chunked encoding streaming mode for output.
protected  int fixedContentLength sample code for java.net.HttpURLConnection.fixedContentLength definition code for java.net.HttpURLConnection.fixedContentLength
          The fixed content-length when using fixed-length streaming mode.
static int HTTP_ACCEPTED sample code for java.net.HttpURLConnection.HTTP_ACCEPTED definition code for java.net.HttpURLConnection.HTTP_ACCEPTED
          HTTP Status-Code 202: Accepted.
static int HTTP_BAD_GATEWAY sample code for java.net.HttpURLConnection.HTTP_BAD_GATEWAY definition code for java.net.HttpURLConnection.HTTP_BAD_GATEWAY
          HTTP Status-Code 502: Bad Gateway.
static int HTTP_BAD_METHOD sample code for java.net.HttpURLConnection.HTTP_BAD_METHOD definition code for java.net.HttpURLConnection.HTTP_BAD_METHOD
          HTTP Status-Code 405: Method Not Allowed.
static int HTTP_BAD_REQUEST sample code for java.net.HttpURLConnection.HTTP_BAD_REQUEST definition code for java.net.HttpURLConnection.HTTP_BAD_REQUEST
          HTTP Status-Code 400: Bad Request.
static int HTTP_CLIENT_TIMEOUT sample code for java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT definition code for java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT
          HTTP Status-Code 408: Request Time-Out.
static int HTTP_CONFLICT sample code for java.net.HttpURLConnection.HTTP_CONFLICT definition code for java.net.HttpURLConnection.HTTP_CONFLICT
          HTTP Status-Code 409: Conflict.
static int HTTP_CREATED sample code for java.net.HttpURLConnection.HTTP_CREATED definition code for java.net.HttpURLConnection.HTTP_CREATED
          HTTP Status-Code 201: Created.
static int HTTP_ENTITY_TOO_LARGE sample code for java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE definition code for java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE
          HTTP Status-Code 413: Request Entity Too Large.
static int HTTP_FORBIDDEN sample code for java.net.HttpURLConnection.HTTP_FORBIDDEN definition code for java.net.HttpURLConnection.HTTP_FORBIDDEN
          HTTP Status-Code 403: Forbidden.
static int HTTP_GATEWAY_TIMEOUT sample code for java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT definition code for java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT
          HTTP Status-Code 504: Gateway Timeout.
static int HTTP_GONE sample code for java.net.HttpURLConnection.HTTP_GONE definition code for java.net.HttpURLConnection.HTTP_GONE
          HTTP Status-Code 410: Gone.
static int HTTP_INTERNAL_ERROR sample code for java.net.HttpURLConnection.HTTP_INTERNAL_ERROR definition code for java.net.HttpURLConnection.HTTP_INTERNAL_ERROR
          HTTP Status-Code 500: Internal Server Error.
static int HTTP_LENGTH_REQUIRED sample code for java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED definition code for java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED
          HTTP Status-Code 411: Length Required.
static int HTTP_MOVED_PERM sample code for java.net.HttpURLConnection.HTTP_MOVED_PERM definition code for java.net.HttpURLConnection.HTTP_MOVED_PERM
          HTTP Status-Code 301: Moved Permanently.
static int HTTP_MOVED_TEMP sample code for java.net.HttpURLConnection.HTTP_MOVED_TEMP definition code for java.net.HttpURLConnection.HTTP_MOVED_TEMP
          HTTP Status-Code 302: Temporary Redirect.
static int HTTP_MULT_CHOICE sample code for java.net.HttpURLConnection.HTTP_MULT_CHOICE definition code for java.net.HttpURLConnection.HTTP_MULT_CHOICE
          HTTP Status-Code 300: Multiple Choices.
static int HTTP_NO_CONTENT sample code for java.net.HttpURLConnection.HTTP_NO_CONTENT definition code for java.net.HttpURLConnection.HTTP_NO_CONTENT
          HTTP Status-Code 204: No Content.
static int HTTP_NOT_ACCEPTABLE sample code for java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE definition code for java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE
          HTTP Status-Code 406: Not Acceptable.
static int HTTP_NOT_AUTHORITATIVE sample code for java.net.HttpURLConnection.HTTP_NOT_AUTHORITATIVE definition code for java.net.HttpURLConnection.HTTP_NOT_AUTHORITATIVE
          HTTP Status-Code 203: Non-Authoritative Information.
static int HTTP_NOT_FOUND sample code for java.net.HttpURLConnection.HTTP_NOT_FOUND definition code for java.net.HttpURLConnection.HTTP_NOT_FOUND
          HTTP Status-Code 404: Not Found.
static int HTTP_NOT_IMPLEMENTED sample code for java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED definition code for java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED
          HTTP Status-Code 501: Not Implemented.
static int HTTP_NOT_MODIFIED sample code for java.net.HttpURLConnection.HTTP_NOT_MODIFIED definition code for java.net.HttpURLConnection.HTTP_NOT_MODIFIED
          HTTP Status-Code 304: Not Modified.
static int HTTP_OK sample code for java.net.HttpURLConnection.HTTP_OK definition code for java.net.HttpURLConnection.HTTP_OK
          HTTP Status-Code 200: OK.
static int HTTP_PARTIAL sample code for java.net.HttpURLConnection.HTTP_PARTIAL definition code for java.net.HttpURLConnection.HTTP_PARTIAL
          HTTP Status-Code 206: Partial Content.
static int HTTP_PAYMENT_REQUIRED sample code for java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED definition code for java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED
          HTTP Status-Code 402: Payment Required.
static int HTTP_PRECON_FAILED sample code for java.net.HttpURLConnection.HTTP_PRECON_FAILED definition code for java.net.HttpURLConnection.HTTP_PRECON_FAILED
          HTTP Status-Code 412: Precondition Failed.
static int HTTP_PROXY_AUTH sample code for java.net.HttpURLConnection.HTTP_PROXY_AUTH definition code for java.net.HttpURLConnection.HTTP_PROXY_AUTH
          HTTP Status-Code 407: Proxy Authentication Required.
static int HTTP_REQ_TOO_LONG sample code for java.net.HttpURLConnection.HTTP_REQ_TOO_LONG definition code for java.net.HttpURLConnection.HTTP_REQ_TOO_LONG
          HTTP Status-Code 414: Request-URI Too Large.
static int HTTP_RESET sample code for java.net.HttpURLConnection.HTTP_RESET definition code for java.net.HttpURLConnection.HTTP_RESET
          HTTP Status-Code 205: Reset Content.
static int HTTP_SEE_OTHER sample code for java.net.HttpURLConnection.HTTP_SEE_OTHER definition code for java.net.HttpURLConnection.HTTP_SEE_OTHER
          HTTP Status-Code 303: See Other.
static int HTTP_SERVER_ERROR sample code for java.net.HttpURLConnection.HTTP_SERVER_ERROR definition code for java.net.HttpURLConnection.HTTP_SERVER_ERROR
          Deprecated. it is misplaced and shouldn't have existed.
static int HTTP_UNAUTHORIZED sample code for java.net.HttpURLConnection.HTTP_UNAUTHORIZED definition code for java.net.HttpURLConnection.HTTP_UNAUTHORIZED
          HTTP Status-Code 401: Unauthorized.
static int HTTP_UNAVAILABLE sample code for java.net.HttpURLConnection.HTTP_UNAVAILABLE definition code for java.net.HttpURLConnection.HTTP_UNAVAILABLE
          HTTP Status-Code 503: Service Unavailable.
static int HTTP_UNSUPPORTED_TYPE sample code for java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE definition code for java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE
          HTTP Status-Code 415: Unsupported Media Type.
static int HTTP_USE_PROXY sample code for java.net.HttpURLConnection.HTTP_USE_PROXY definition code for java.net.HttpURLConnection.HTTP_USE_PROXY
          HTTP Status-Code 305: Use Proxy.
static int HTTP_VERSION sample code for java.net.HttpURLConnection.HTTP_VERSION definition code for java.net.HttpURLConnection.HTTP_VERSION
          HTTP Status-Code 505: HTTP Version Not Supported.
protected  boolean instanceFollowRedirects sample code for java.net.HttpURLConnection.instanceFollowRedirects definition code for java.net.HttpURLConnection.instanceFollowRedirects
          If true, the protocol will automatically follow redirects.
protected  String sample code for java.lang.String definition code for java.lang.String method sample code for java.net.HttpURLConnection.method definition code for java.net.HttpURLConnection.method
          The HTTP method (GET,POST,PUT,etc.).
protected  int responseCode sample code for java.net.HttpURLConnection.responseCode definition code for java.net.HttpURLConnection.responseCode
          An int representing the three digit HTTP Status-Code.
protected  String sample code for java.lang.String definition code for java.lang.String responseMessage sample code for java.net.HttpURLConnection.responseMessage definition code for java.net.HttpURLConnection.responseMessage
          The HTTP response message.
 
Fields inherited from class java.net.URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
allowUserInteraction sample code for java.net.URLConnection.allowUserInteraction definition code for java.net.URLConnection.allowUserInteraction , connected sample code for java.net.URLConnection.connected definition code for java.net.URLConnection.connected , doInput sample code for java.net.URLConnection.doInput definition code for java.net.URLConnection.doInput , doOutput sample code for java.net.URLConnection.doOutput definition code for java.net.URLConnection.doOutput , ifModifiedSince sample code for java.net.URLConnection.ifModifiedSince definition code for java.net.URLConnection.ifModifiedSince , url sample code for java.net.URLConnection.url definition code for java.net.URLConnection.url , useCaches sample code for java.net.URLConnection.useCaches definition code for java.net.URLConnection.useCaches
 
Constructor Summary
protected HttpURLConnection sample code for java.net.HttpURLConnection.HttpURLConnection(java.net.URL) definition code for java.net.HttpURLConnection.HttpURLConnection(java.net.URL) (URL sample code for java.net.URL definition code for java.net.URL  u)
          Constructor for the HttpURLConnection.
 
Method Summary
abstract  void disconnect sample code for java.net.HttpURLConnection.disconnect() definition code for java.net.HttpURLConnection.disconnect() ()
          Indicates that other requests to the server are unlikely in the near future.
 InputStream sample code for java.io.InputStream definition code for java.io.InputStream getErrorStream sample code for java.net.HttpURLConnection.getErrorStream() definition code for java.net.HttpURLConnection.getErrorStream() ()
          Returns the error stream if the connection failed but the server sent useful data nonetheless.
static boolean getFollowRedirects sample code for java.net.HttpURLConnection.getFollowRedirects() definition code for java.net.HttpURLConnection.getFollowRedirects() ()
          Returns a boolean indicating whether or not HTTP redirects (3xx) should be automatically followed.
 String sample code for java.lang.String definition code for java.lang.String getHeaderField sample code for java.net.HttpURLConnection.getHeaderField(int) definition code for java.net.HttpURLConnection.getHeaderField(int) (int n)
          Returns the value for the nth header field.
 long getHeaderFieldDate sample code for java.net.HttpURLConnection.getHeaderFieldDate(java.lang.String, long) definition code for java.net.HttpURLConnection.getHeaderFieldDate(java.lang.String, long) (String sample code for java.lang.String definition code for java.lang.String  name, long Default)
          Returns the value of the named field parsed as date.
 String sample code for java.lang.String definition code for java.lang.String getHeaderFieldKey sample code for java.net.HttpURLConnection.getHeaderFieldKey(int) definition code for java.net.HttpURLConnection.getHeaderFieldKey(int) (int n)
          Returns the key for the nth header field.
 boolean getInstanceFollowRedirects sample code for java.net.HttpURLConnection.getInstanceFollowRedirects() definition code for java.net.HttpURLConnection.getInstanceFollowRedirects() ()
          Returns the value of this HttpURLConnection's instanceFollowRedirects field.
 Permission sample code for java.security.Permission definition code for java.security.Permission getPermission sample code for java.net.HttpURLConnection.getPermission() definition code for java.net.HttpURLConnection.getPermission() ()
          Returns a permission object representing the permission necessary to make the connection represented by this object.
 String sample code for java.lang.String definition code for java.lang.String getRequestMethod sample code for java.net.HttpURLConnection.getRequestMethod() definition code for java.net.HttpURLConnection.getRequestMethod() ()
          Get the request method.
 int getResponseCode sample code for java.net.HttpURLConnection.getResponseCode() definition code for java.net.HttpURLConnection.getResponseCode() ()
          Gets the status code from an HTTP response message.
 String sample code for java.lang.String definition code for java.lang.String getResponseMessage sample code for java.net.HttpURLConnection.getResponseMessage() definition code for java.net.HttpURLConnection.getResponseMessage() ()
          Gets the HTTP response message, if any, returned along with the response code from a server.
 void setChunkedStreamingMode sample code for java.net.HttpURLConnection.setChunkedStreamingMode(int) definition code for java.net.HttpURLConnection.setChunkedStreamingMode(int) (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.
 void setFixedLengthStreamingMode sample code for java.net.HttpURLConnection.setFixedLengthStreamingMode(int) definition code for java.net.HttpURLConnection.setFixedLengthStreamingMode(int) (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.
static void setFollowRedirects sample code for java.net.HttpURLConnection.setFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setFollowRedirects(boolean) (boolean set)
          Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class.
 void setInstanceFollowRedirects sample code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean) (boolean followRedirects)
          Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance.
 void setRequestMethod sample code for java.net.HttpURLConnection.setRequestMethod(java.lang.String) definition code for java.net.HttpURLConnection.setRequestMethod(java.lang.String) (String sample code for java.lang.String definition code for java.lang.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  boolean usingProxy sample code for java.net.HttpURLConnection.usingProxy() definition code for java.net.HttpURLConnection.usingProxy() ()
          Indicates if the connection is going through a proxy.
 
Methods inherited from class java.net.URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
addRequestProperty sample code for java.net.URLConnection.addRequestProperty(java.lang.String, java.lang.String) definition code for java.net.URLConnection.addRequestProperty(java.lang.String, java.lang.String) , connect sample code for java.net.URLConnection.connect() definition code for java.net.URLConnection.connect() , getAllowUserInteraction sample code for java.net.URLConnection.getAllowUserInteraction() definition code for java.net.URLConnection.getAllowUserInteraction() , getConnectTimeout sample code for java.net.URLConnection.getConnectTimeout() definition code for java.net.URLConnection.getConnectTimeout() , getContent sample code for java.net.URLConnection.getContent() definition code for java.net.URLConnection.getContent() , getContent sample code for java.net.URLConnection.getContent(java.lang.Class[]) definition code for java.net.URLConnection.getContent(java.lang.Class[]) , getContentEncoding sample code for java.net.URLConnection.getContentEncoding() definition code for java.net.URLConnection.getContentEncoding() , getContentLength sample code for java.net.URLConnection.getContentLength() definition code for java.net.URLConnection.getContentLength() , getContentType sample code for java.net.URLConnection.getContentType() definition code for java.net.URLConnection.getContentType() , getDate sample code for java.net.URLConnection.getDate() definition code for java.net.URLConnection.getDate() , getDefaultAllowUserInteraction sample code for java.net.URLConnection.getDefaultAllowUserInteraction() definition code for java.net.URLConnection.getDefaultAllowUserInteraction() , getDefaultRequestProperty sample code for java.net.URLConnection.getDefaultRequestProperty(java.lang.String) definition code for java.net.URLConnection.getDefaultRequestProperty(java.lang.String) , getDefaultUseCaches sample code for java.net.URLConnection.getDefaultUseCaches() definition code for java.net.URLConnection.getDefaultUseCaches() , getDoInput sample code for java.net.URLConnection.getDoInput() definition code for java.net.URLConnection.getDoInput() , getDoOutput sample code for java.net.URLConnection.getDoOutput() definition code for java.net.URLConnection.getDoOutput() , getExpiration sample code for java.net.URLConnection.getExpiration() definition code for java.net.URLConnection.getExpiration() , getFileNameMap sample code for java.net.URLConnection.getFileNameMap() definition code for java.net.URLConnection.getFileNameMap() , getHeaderField sample code for java.net.URLConnection.getHeaderField(java.lang.String) definition code for java.net.URLConnection.getHeaderField(java.lang.String) , getHeaderFieldInt sample code for java.net.URLConnection.getHeaderFieldInt(java.lang.String, int) definition code for java.net.URLConnection.getHeaderFieldInt(java.lang.String, int) , getHeaderFields sample code for java.net.URLConnection.getHeaderFields() definition code for java.net.URLConnection.getHeaderFields() , getIfModifiedSince sample code for java.net.URLConnection.getIfModifiedSince() definition code for java.net.URLConnection.getIfModifiedSince() , getInputStream sample code for java.net.URLConnection.getInputStream() definition code for java.net.URLConnection.getInputStream() , getLastModified sample code for java.net.URLConnection.getLastModified() definition code for java.net.URLConnection.getLastModified() , getOutputStream sample code for java.net.URLConnection.getOutputStream() definition code for java.net.URLConnection.getOutputStream() , getReadTimeout sample code for java.net.URLConnection.getReadTimeout() definition code for java.net.URLConnection.getReadTimeout() , getRequestProperties sample code for java.net.URLConnection.getRequestProperties() definition code for java.net.URLConnection.getRequestProperties() , getRequestProperty sample code for java.net.URLConnection.getRequestProperty(java.lang.String) definition code for java.net.URLConnection.getRequestProperty(java.lang.String) , getURL sample code for java.net.URLConnection.getURL() definition code for java.net.URLConnection.getURL() , getUseCaches sample code for java.net.URLConnection.getUseCaches() definition code for java.net.URLConnection.getUseCaches() , guessContentTypeFromName sample code for java.net.URLConnection.guessContentTypeFromName(java.lang.String) definition code for java.net.URLConnection.guessContentTypeFromName(java.lang.String) , guessContentTypeFromStream sample code for java.net.URLConnection.guessContentTypeFromStream(java.io.InputStream) definition code for java.net.URLConnection.guessContentTypeFromStream(java.io.InputStream) , setAllowUserInteraction sample code for java.net.URLConnection.setAllowUserInteraction(boolean) definition code for java.net.URLConnection.setAllowUserInteraction(boolean) , setConnectTimeout sample code for java.net.URLConnection.setConnectTimeout(int) definition code for java.net.URLConnection.setConnectTimeout(int) , setContentHandlerFactory sample code for java.net.URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory) definition code for java.net.URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory) , setDefaultAllowUserInteraction sample code for java.net.URLConnection.setDefaultAllowUserInteraction(boolean) definition code for java.net.URLConnection.setDefaultAllowUserInteraction(boolean) , setDefaultRequestProperty sample code for java.net.URLConnection.setDefaultRequestProperty(java.lang.String, java.lang.String) definition code for java.net.URLConnection.setDefaultRequestProperty(java.lang.String, java.lang.String) , setDefaultUseCaches sample code for java.net.URLConnection.setDefaultUseCaches(boolean) definition code for java.net.URLConnection.setDefaultUseCaches(boolean) , setDoInput sample code for java.net.URLConnection.setDoInput(boolean) definition code for java.net.URLConnection.setDoInput(boolean) , setDoOutput sample code for java.net.URLConnection.setDoOutput(boolean) definition code for java.net.URLConnection.setDoOutput(boolean) , setFileNameMap sample code for java.net.URLConnection.setFileNameMap(java.net.FileNameMap) definition code for java.net.URLConnection.setFileNameMap(java.net.FileNameMap) , setIfModifiedSince sample code for java.net.URLConnection.setIfModifiedSince(long) definition code for java.net.URLConnection.setIfModifiedSince(long) , setReadTimeout sample code for java.net.URLConnection.setReadTimeout(int) definition code for java.net.URLConnection.setReadTimeout(int) , setRequestProperty sample code for java.net.URLConnection.setRequestProperty(java.lang.String, java.lang.String) definition code for java.net.URLConnection.setRequestProperty(java.lang.String, java.lang.String) , setUseCaches sample code for java.net.URLConnection.setUseCaches(boolean) definition code for java.net.URLConnection.setUseCaches(boolean) , toString sample code for java.net.URLConnection.toString() definition code for java.net.URLConnection.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

method sample code for java.net.HttpURLConnection.method

protected String sample code for java.lang.String definition code for java.lang.String  method
The HTTP method (GET,POST,PUT,etc.).


chunkLength sample code for java.net.HttpURLConnection.chunkLength

protected int chunkLength
The chunk-length when using chunked encoding streaming mode for output. A value of -1 means chunked encoding is disabled for output.


fixedContentLength sample code for java.net.HttpURLConnection.fixedContentLength

protected int fixedContentLength
The fixed content-length when using fixed-length streaming mode. A value of -1 means fixed-length streaming mode is disabled for output.


responseCode sample code for java.net.HttpURLConnection.responseCode

protected int responseCode
An int representing the three digit HTTP Status-Code.


responseMessage sample code for java.net.HttpURLConnection.responseMessage

protected String sample code for java.lang.String definition code for java.lang.String  responseMessage
The HTTP response message.


instanceFollowRedirects sample code for java.net.HttpURLConnection.instanceFollowRedirects

protected boolean instanceFollowRedirects
If true, the protocol will automatically follow redirects. If false, the protocol will not automatically follow redirects.

This field is set by the setInstanceFollowRedirects method. Its value is returned by the getInstanceFollowRedirects method.

Its default value is based on the value of the static followRedirects at HttpURLConnection construction time.

See Also:
setInstanceFollowRedirects(boolean) sample code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean) , getInstanceFollowRedirects() sample code for java.net.HttpURLConnection.getInstanceFollowRedirects() definition code for java.net.HttpURLConnection.getInstanceFollowRedirects() , setFollowRedirects(boolean) sample code for java.net.HttpURLConnection.setFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setFollowRedirects(boolean)

HTTP_OK sample code for java.net.HttpURLConnection.HTTP_OK

public static final int HTTP_OK
HTTP Status-Code 200: OK.

See Also:
Constant Field Values

HTTP_CREATED sample code for java.net.HttpURLConnection.HTTP_CREATED

public static final int HTTP_CREATED
HTTP Status-Code 201: Created.

See Also:
Constant Field Values

HTTP_ACCEPTED sample code for java.net.HttpURLConnection.HTTP_ACCEPTED

public static final int HTTP_ACCEPTED
HTTP Status-Code 202: Accepted.

See Also:
Constant Field Values

HTTP_NOT_AUTHORITATIVE sample code for java.net.HttpURLConnection.HTTP_NOT_AUTHORITATIVE

public static final int HTTP_NOT_AUTHORITATIVE
HTTP Status-Code 203: Non-Authoritative Information.

See Also:
Constant Field Values

HTTP_NO_CONTENT sample code for java.net.HttpURLConnection.HTTP_NO_CONTENT

public static final int HTTP_NO_CONTENT
HTTP Status-Code 204: No Content.

See Also:
Constant Field Values

HTTP_RESET sample code for java.net.HttpURLConnection.HTTP_RESET

public static final int HTTP_RESET
HTTP Status-Code 205: Reset Content.

See Also:
Constant Field Values

HTTP_PARTIAL sample code for java.net.HttpURLConnection.HTTP_PARTIAL

public static final int HTTP_PARTIAL
HTTP Status-Code 206: Partial Content.

See Also:
Constant Field Values

HTTP_MULT_CHOICE sample code for java.net.HttpURLConnection.HTTP_MULT_CHOICE

public static final int HTTP_MULT_CHOICE
HTTP Status-Code 300: Multiple Choices.

See Also:
Constant Field Values

HTTP_MOVED_PERM sample code for java.net.HttpURLConnection.HTTP_MOVED_PERM

public static final int HTTP_MOVED_PERM
HTTP Status-Code 301: Moved Permanently.

See Also:
Constant Field Values

HTTP_MOVED_TEMP sample code for java.net.HttpURLConnection.HTTP_MOVED_TEMP

public static final int HTTP_MOVED_TEMP
HTTP Status-Code 302: Temporary Redirect.

See Also:
Constant Field Values

HTTP_SEE_OTHER sample code for java.net.HttpURLConnection.HTTP_SEE_OTHER

public static final int HTTP_SEE_OTHER
HTTP Status-Code 303: See Other.

See Also:
Constant Field Values

HTTP_NOT_MODIFIED sample code for java.net.HttpURLConnection.HTTP_NOT_MODIFIED

public static final int HTTP_NOT_MODIFIED
HTTP Status-Code 304: Not Modified.

See Also:
Constant Field Values

HTTP_USE_PROXY sample code for java.net.HttpURLConnection.HTTP_USE_PROXY

public static final int HTTP_USE_PROXY
HTTP Status-Code 305: Use Proxy.

See Also:
Constant Field Values

HTTP_BAD_REQUEST sample code for java.net.HttpURLConnection.HTTP_BAD_REQUEST

public static final int HTTP_BAD_REQUEST
HTTP Status-Code 400: Bad Request.

See Also:
Constant Field Values

HTTP_UNAUTHORIZED sample code for java.net.HttpURLConnection.HTTP_UNAUTHORIZED

public static final int HTTP_UNAUTHORIZED
HTTP Status-Code 401: Unauthorized.

See Also:
Constant Field Values

HTTP_PAYMENT_REQUIRED sample code for java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED

public static final int HTTP_PAYMENT_REQUIRED
HTTP Status-Code 402: Payment Required.

See Also:
Constant Field Values

HTTP_FORBIDDEN sample code for java.net.HttpURLConnection.HTTP_FORBIDDEN

public static final int HTTP_FORBIDDEN
HTTP Status-Code 403: Forbidden.

See Also:
Constant Field Values

HTTP_NOT_FOUND sample code for java.net.HttpURLConnection.HTTP_NOT_FOUND

public static final int HTTP_NOT_FOUND
HTTP Status-Code 404: Not Found.

See Also:
Constant Field Values

HTTP_BAD_METHOD sample code for java.net.HttpURLConnection.HTTP_BAD_METHOD

public static final int HTTP_BAD_METHOD
HTTP Status-Code 405: Method Not Allowed.

See Also:
Constant Field Values

HTTP_NOT_ACCEPTABLE sample code for java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE

public static final int HTTP_NOT_ACCEPTABLE
HTTP Status-Code 406: Not Acceptable.

See Also:
Constant Field Values

HTTP_PROXY_AUTH sample code for java.net.HttpURLConnection.HTTP_PROXY_AUTH

public static final int HTTP_PROXY_AUTH
HTTP Status-Code 407: Proxy Authentication Required.

See Also:
Constant Field Values

HTTP_CLIENT_TIMEOUT sample code for java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT

public static final int HTTP_CLIENT_TIMEOUT
HTTP Status-Code 408: Request Time-Out.

See Also:
Constant Field Values

HTTP_CONFLICT sample code for java.net.HttpURLConnection.HTTP_CONFLICT

public static final int HTTP_CONFLICT
HTTP Status-Code 409: Conflict.

See Also:
Constant Field Values

HTTP_GONE sample code for java.net.HttpURLConnection.HTTP_GONE

public static final int HTTP_GONE
HTTP Status-Code 410: Gone.

See Also:
Constant Field Values

HTTP_LENGTH_REQUIRED sample code for java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED

public static final int HTTP_LENGTH_REQUIRED
HTTP Status-Code 411: Length Required.

See Also:
Constant Field Values

HTTP_PRECON_FAILED sample code for java.net.HttpURLConnection.HTTP_PRECON_FAILED

public static final int HTTP_PRECON_FAILED
HTTP Status-Code 412: Precondition Failed.

See Also:
Constant Field Values

HTTP_ENTITY_TOO_LARGE sample code for java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE

public static final int HTTP_ENTITY_TOO_LARGE
HTTP Status-Code 413: Request Entity Too Large.

See Also:
Constant Field Values

HTTP_REQ_TOO_LONG sample code for java.net.HttpURLConnection.HTTP_REQ_TOO_LONG

public static final int HTTP_REQ_TOO_LONG
HTTP Status-Code 414: Request-URI Too Large.

See Also:
Constant Field Values

HTTP_UNSUPPORTED_TYPE sample code for java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE

public static final int HTTP_UNSUPPORTED_TYPE
HTTP Status-Code 415: Unsupported Media Type.

See Also:
Constant Field Values

HTTP_SERVER_ERROR sample code for java.net.HttpURLConnection.HTTP_SERVER_ERROR

@Deprecated
public static final int HTTP_SERVER_ERROR
Deprecated. it is misplaced and shouldn't have existed.
HTTP Status-Code 500: Internal Server Error.

See Also:
Constant Field Values

HTTP_INTERNAL_ERROR sample code for java.net.HttpURLConnection.HTTP_INTERNAL_ERROR

public static final int HTTP_INTERNAL_ERROR
HTTP Status-Code 500: Internal Server Error.

See Also:
Constant Field Values

HTTP_NOT_IMPLEMENTED sample code for java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED

public static final int HTTP_NOT_IMPLEMENTED
HTTP Status-Code 501: Not Implemented.

See Also:
Constant Field Values

HTTP_BAD_GATEWAY sample code for java.net.HttpURLConnection.HTTP_BAD_GATEWAY

public static final int HTTP_BAD_GATEWAY
HTTP Status-Code 502: Bad Gateway.

See Also:
Constant Field Values

HTTP_UNAVAILABLE sample code for java.net.HttpURLConnection.HTTP_UNAVAILABLE

public static final int HTTP_UNAVAILABLE
HTTP Status-Code 503: Service Unavailable.

See Also:
Constant Field Values

HTTP_GATEWAY_TIMEOUT sample code for java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT

public static final int HTTP_GATEWAY_TIMEOUT
HTTP Status-Code 504: Gateway Timeout.

See Also:
Constant Field Values

HTTP_VERSION sample code for java.net.HttpURLConnection.HTTP_VERSION

public static final int HTTP_VERSION
HTTP Status-Code 505: HTTP Version Not Supported.

See Also:
Constant Field Values
Constructor Detail

HttpURLConnection sample code for java.net.HttpURLConnection(java.net.URL) definition code for java.net.HttpURLConnection(java.net.URL)

protected HttpURLConnection(URL sample code for java.net.URL definition code for java.net.URL  u)
Constructor for the HttpURLConnection.

Parameters:
u - the URL
Method Detail

getHeaderFieldKey sample code for java.net.HttpURLConnection.getHeaderFieldKey(int) definition code for java.net.HttpURLConnection.getHeaderFieldKey(int)

public String sample code for java.lang.String definition code for java.lang.String  getHeaderFieldKey(int n)
Returns the key for the nth header field. Some implementations may treat the 0th header field as special, i.e. as the status line returned by the HTTP server. In this case, getHeaderField(0) sample code for java.net.HttpURLConnection.getHeaderField(int) definition code for java.net.HttpURLConnection.getHeaderField(int) returns the status line, but getHeaderFieldKey(0) returns null.

Overrides:
getHeaderFieldKey sample code for java.net.URLConnection.getHeaderFieldKey(int) definition code for java.net.URLConnection.getHeaderFieldKey(int) in class URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
Parameters:
n - an index, where n >=0.
Returns:
the key for the nth header field, or null if the key does not exist.

setFixedLengthStreamingMode sample code for java.net.HttpURLConnection.setFixedLengthStreamingMode(int) definition code for java.net.HttpURLConnection.setFixedLengthStreamingMode(int)

public void setFixedLengthStreamingMode(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.

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.

Parameters:
contentLength - The number of bytes which will be written to the OutputStream.
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if a content length less than zero is specified.
See Also:
setChunkedStreamingMode(int) sample code for java.net.HttpURLConnection.setChunkedStreamingMode(int) definition code for java.net.HttpURLConnection.setChunkedStreamingMode(int)

setChunkedStreamingMode sample code for java.net.HttpURLConnection.setChunkedStreamingMode(int) definition code for java.net.HttpURLConnection.setChunkedStreamingMode(int)

public void setChunkedStreamingMode(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. 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.

Parameters:
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.
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
See Also:
setFixedLengthStreamingMode(int) sample code for java.net.HttpURLConnection.setFixedLengthStreamingMode(int) definition code for java.net.HttpURLConnection.setFixedLengthStreamingMode(int)

getHeaderField sample code for java.net.HttpURLConnection.getHeaderField(int) definition code for java.net.HttpURLConnection.getHeaderField(int)

public String sample code for java.lang.String definition code for java.lang.String  getHeaderField(int n)
Returns the value for the nth header field. Some implementations may treat the 0th header field as special, i.e. as the status line returned by the HTTP server.

This method can be used in conjunction with the getHeaderFieldKey sample code for java.net.HttpURLConnection.getHeaderFieldKey(int) definition code for java.net.HttpURLConnection.getHeaderFieldKey(int) method to iterate through all the headers in the message.

Overrides:
getHeaderField sample code for java.net.URLConnection.getHeaderField(int) definition code for java.net.URLConnection.getHeaderField(int) in class URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
Parameters:
n - an index, where n>=0.
Returns:
the value of the nth header field, or null if the value does not exist.
See Also:
getHeaderFieldKey(int) sample code for java.net.HttpURLConnection.getHeaderFieldKey(int) definition code for java.net.HttpURLConnection.getHeaderFieldKey(int)

setFollowRedirects sample code for java.net.HttpURLConnection.setFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setFollowRedirects(boolean)

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. Applets cannot change this variable.

If there is a security manager, this method first calls the security manager's checkSetFactory method to ensure the operation is allowed. This could result in a SecurityException.

Parameters:
set - a boolean indicating whether or not to follow HTTP redirects.
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation.
See Also:
SecurityManager.checkSetFactory() sample code for java.lang.SecurityManager.checkSetFactory() definition code for java.lang.SecurityManager.checkSetFactory() , getFollowRedirects() sample code for java.net.HttpURLConnection.getFollowRedirects() definition code for java.net.HttpURLConnection.getFollowRedirects()

getFollowRedirects sample code for java.net.HttpURLConnection.getFollowRedirects() definition code for java.net.HttpURLConnection.getFollowRedirects()

public static boolean getFollowRedirects()
Returns a boolean indicating whether or not HTTP redirects (3xx) should be automatically followed.

Returns:
true if HTTP redirects should be automatically followed, false if not.
See Also:
setFollowRedirects(boolean) sample code for java.net.HttpURLConnection.setFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setFollowRedirects(boolean)

setInstanceFollowRedirects sample code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean)

public void setInstanceFollowRedirects(boolean followRedirects)
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.

Parameters:
followRedirects - a boolean indicating whether or not to follow HTTP redirects.
See Also:
instanceFollowRedirects sample code for java.net.HttpURLConnection.instanceFollowRedirects definition code for java.net.HttpURLConnection.instanceFollowRedirects , getInstanceFollowRedirects() sample code for java.net.HttpURLConnection.getInstanceFollowRedirects() definition code for java.net.HttpURLConnection.getInstanceFollowRedirects()

getInstanceFollowRedirects sample code for java.net.HttpURLConnection.getInstanceFollowRedirects() definition code for java.net.HttpURLConnection.getInstanceFollowRedirects()

public boolean getInstanceFollowRedirects()
Returns the value of this HttpURLConnection's instanceFollowRedirects field.

Returns:
the value of this HttpURLConnection's instanceFollowRedirects field.
See Also:
instanceFollowRedirects sample code for java.net.HttpURLConnection.instanceFollowRedirects definition code for java.net.HttpURLConnection.instanceFollowRedirects , setInstanceFollowRedirects(boolean) sample code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean) definition code for java.net.HttpURLConnection.setInstanceFollowRedirects(boolean)

setRequestMethod sample code for java.net.HttpURLConnection.setRequestMethod(java.lang.String) definition code for java.net.HttpURLConnection.setRequestMethod(java.lang.String)

public void setRequestMethod(String sample code for java.lang.String definition code for java.lang.String  method)
                      throws ProtocolException sample code for java.net.ProtocolException definition code for java.net.ProtocolException 
Set the method for the URL request, one of: are legal, subject to protocol restrictions. The default method is GET.

Parameters:
method - the HTTP method
Throws:
ProtocolException sample code for java.net.ProtocolException definition code for java.net.ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.
See Also:
getRequestMethod() sample code for java.net.HttpURLConnection.getRequestMethod() definition code for java.net.HttpURLConnection.getRequestMethod()

getRequestMethod sample code for java.net.HttpURLConnection.getRequestMethod() definition code for java.net.HttpURLConnection.getRequestMethod()

public String sample code for java.lang.String definition code for java.lang.String  getRequestMethod()
Get the request method.

Returns:
the HTTP request method
See Also:
setRequestMethod(java.lang.String) sample code for java.net.HttpURLConnection.setRequestMethod(java.lang.String) definition code for java.net.HttpURLConnection.setRequestMethod(java.lang.String)

getResponseCode sample code for java.net.HttpURLConnection.getResponseCode() definition code for java.net.HttpURLConnection.getResponseCode()

public int getResponseCode()
                    throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Gets the status code from an HTTP response message. For example, in the case of the following status lines:
 HTTP/1.0 200 OK
 HTTP/1.0 401 Unauthorized
 
It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP).

Returns:
the HTTP Status-Code, or -1
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an error occurred connecting to the server.

getResponseMessage sample code for java.net.HttpURLConnection.getResponseMessage() definition code for java.net.HttpURLConnection.getResponseMessage()

public String sample code for java.lang.String definition code for java.lang.String  getResponseMessage()
                          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
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 Found
 
Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).

Returns:
the HTTP response message, or null
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an error occurred connecting to the server.

getHeaderFieldDate sample code for java.net.HttpURLConnection.getHeaderFieldDate(java.lang.String, long) definition code for java.net.HttpURLConnection.getHeaderFieldDate(java.lang.String, long)

public long getHeaderFieldDate(String sample code for java.lang.String definition code for java.lang.String  name,
                               long Default)
Description copied from class: URLConnection sample code for java.net.URLConnection.getHeaderFieldDate(java.lang.String, long) definition code for java.net.URLConnection.getHeaderFieldDate(java.lang.String, long)
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.

Overrides:
getHeaderFieldDate sample code for java.net.URLConnection.getHeaderFieldDate(java.lang.String, long) definition code for java.net.URLConnection.getHeaderFieldDate(java.lang.String, long) in class URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
Parameters:
name - the name of the header field.
Default - a default value.
Returns:
the value of the field, parsed as a date. The value of the Default argument is returned if the field is missing or malformed.

disconnect sample code for java.net.HttpURLConnection.disconnect() definition code for java.net.HttpURLConnection.disconnect()

public abstract void disconnect()
Indicates that other requests to the server are unlikely in the near future. Calling disconnect() should not imply that this HttpURLConnection instance can be reused for other requests.


usingProxy sample code for java.net.HttpURLConnection.usingProxy() definition code for java.net.HttpURLConnection.usingProxy()

public abstract boolean usingProxy()
Indicates if the connection is going through a proxy.

Returns:
a boolean indicating if the connection is using a proxy.

getPermission sample code for java.net.HttpURLConnection.getPermission() definition code for java.net.HttpURLConnection.getPermission()

public Permission sample code for java.security.Permission definition code for java.security.Permission  getPermission()
                         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Description copied from class: URLConnection sample code for java.net.URLConnection.getPermission() definition code for java.net.URLConnection.getPermission()
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.

Overrides:
getPermission sample code for java.net.URLConnection.getPermission() definition code for java.net.URLConnection.getPermission() in class URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
Returns:
the permission object representing the permission necessary to make the connection represented by this URLConnection.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the computation of the permission requires network or file I/O and an exception occurs while computing it.

getErrorStream sample code for java.net.HttpURLConnection.getErrorStream() definition code for java.net.HttpURLConnection.getErrorStream()

public InputStream sample code for java.io.InputStream definition code for java.io.InputStream  getErrorStream()
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:
an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.