Liking cljdoc? Tell your friends :D

jdk.net.HttpURLConnection

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 SocketPermission to the host/port combination of the destination URL or a URLPermission that 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.

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` SocketPermission to the host/port combination of the
destination URL or
a URLPermission that 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.
raw docstring

*-http-acceptedclj

Static Constant.

HTTP Status-Code 202: Accepted.

type: int

Static Constant.

HTTP Status-Code 202: Accepted.

type: int
raw docstring

*-http-bad-gatewayclj

Static Constant.

HTTP Status-Code 502: Bad Gateway.

type: int

Static Constant.

HTTP Status-Code 502: Bad Gateway.

type: int
raw docstring

*-http-bad-methodclj

Static Constant.

HTTP Status-Code 405: Method Not Allowed.

type: int

Static Constant.

HTTP Status-Code 405: Method Not Allowed.

type: int
raw docstring

*-http-bad-requestclj

Static Constant.

HTTP Status-Code 400: Bad Request.

type: int

Static Constant.

HTTP Status-Code 400: Bad Request.

type: int
raw docstring

*-http-client-timeoutclj

Static Constant.

HTTP Status-Code 408: Request Time-Out.

type: int

Static Constant.

HTTP Status-Code 408: Request Time-Out.

type: int
raw docstring

*-http-conflictclj

Static Constant.

HTTP Status-Code 409: Conflict.

type: int

Static Constant.

HTTP Status-Code 409: Conflict.

type: int
raw docstring

*-http-createdclj

Static Constant.

HTTP Status-Code 201: Created.

type: int

Static Constant.

HTTP Status-Code 201: Created.

type: int
raw docstring

*-http-entity-too-largeclj

Static Constant.

HTTP Status-Code 413: Request Entity Too Large.

type: int

Static Constant.

HTTP Status-Code 413: Request Entity Too Large.

type: int
raw docstring

*-http-forbiddenclj

Static Constant.

HTTP Status-Code 403: Forbidden.

type: int

Static Constant.

HTTP Status-Code 403: Forbidden.

type: int
raw docstring

*-http-gateway-timeoutclj

Static Constant.

HTTP Status-Code 504: Gateway Timeout.

type: int

Static Constant.

HTTP Status-Code 504: Gateway Timeout.

type: int
raw docstring

*-http-goneclj

Static Constant.

HTTP Status-Code 410: Gone.

type: int

Static Constant.

HTTP Status-Code 410: Gone.

type: int
raw docstring

*-http-internal-errorclj

Static Constant.

HTTP Status-Code 500: Internal Server Error.

type: int

Static Constant.

HTTP Status-Code 500: Internal Server Error.

type: int
raw docstring

*-http-length-requiredclj

Static Constant.

HTTP Status-Code 411: Length Required.

type: int

Static Constant.

HTTP Status-Code 411: Length Required.

type: int
raw docstring

*-http-moved-permclj

Static Constant.

HTTP Status-Code 301: Moved Permanently.

type: int

Static Constant.

HTTP Status-Code 301: Moved Permanently.

type: int
raw docstring

*-http-moved-tempclj

Static Constant.

HTTP Status-Code 302: Temporary Redirect.

type: int

Static Constant.

HTTP Status-Code 302: Temporary Redirect.

type: int
raw docstring

*-http-mult-choiceclj

Static Constant.

HTTP Status-Code 300: Multiple Choices.

type: int

Static Constant.

HTTP Status-Code 300: Multiple Choices.

type: int
raw docstring

*-http-no-contentclj

Static Constant.

HTTP Status-Code 204: No Content.

type: int

Static Constant.

HTTP Status-Code 204: No Content.

type: int
raw docstring

*-http-not-acceptableclj

Static Constant.

HTTP Status-Code 406: Not Acceptable.

type: int

Static Constant.

HTTP Status-Code 406: Not Acceptable.

type: int
raw docstring

*-http-not-authoritativeclj

Static Constant.

HTTP Status-Code 203: Non-Authoritative Information.

type: int

Static Constant.

HTTP Status-Code 203: Non-Authoritative Information.

type: int
raw docstring

*-http-not-foundclj

Static Constant.

HTTP Status-Code 404: Not Found.

type: int

Static Constant.

HTTP Status-Code 404: Not Found.

type: int
raw docstring

*-http-not-implementedclj

Static Constant.

HTTP Status-Code 501: Not Implemented.

type: int

Static Constant.

HTTP Status-Code 501: Not Implemented.

type: int
raw docstring

*-http-not-modifiedclj

Static Constant.

HTTP Status-Code 304: Not Modified.

type: int

Static Constant.

HTTP Status-Code 304: Not Modified.

type: int
raw docstring

*-http-okclj

Static Constant.

HTTP Status-Code 200: OK.

type: int

Static Constant.

HTTP Status-Code 200: OK.

type: int
raw docstring

*-http-partialclj

Static Constant.

HTTP Status-Code 206: Partial Content.

type: int

Static Constant.

HTTP Status-Code 206: Partial Content.

type: int
raw docstring

*-http-payment-requiredclj

Static Constant.

HTTP Status-Code 402: Payment Required.

type: int

Static Constant.

HTTP Status-Code 402: Payment Required.

type: int
raw docstring

*-http-precon-failedclj

Static Constant.

HTTP Status-Code 412: Precondition Failed.

type: int

Static Constant.

HTTP Status-Code 412: Precondition Failed.

type: int
raw docstring

*-http-proxy-authclj

Static Constant.

HTTP Status-Code 407: Proxy Authentication Required.

type: int

Static Constant.

HTTP Status-Code 407: Proxy Authentication Required.

type: int
raw docstring

*-http-req-too-longclj

Static Constant.

HTTP Status-Code 414: Request-URI Too Large.

type: int

Static Constant.

HTTP Status-Code 414: Request-URI Too Large.

type: int
raw docstring

*-http-resetclj

Static Constant.

HTTP Status-Code 205: Reset Content.

type: int

Static Constant.

HTTP Status-Code 205: Reset Content.

type: int
raw docstring

*-http-see-otherclj

Static Constant.

HTTP Status-Code 303: See Other.

type: int

Static Constant.

HTTP Status-Code 303: See Other.

type: int
raw docstring

*-http-server-errorclj

Static Constant.

Deprecated. it is misplaced and shouldn't have existed.

type: java.lang. int

Static Constant.

Deprecated. it is misplaced and shouldn't have existed.

type: java.lang.    int
raw docstring

*-http-unauthorizedclj

Static Constant.

HTTP Status-Code 401: Unauthorized.

type: int

Static Constant.

HTTP Status-Code 401: Unauthorized.

type: int
raw docstring

*-http-unavailableclj

Static Constant.

HTTP Status-Code 503: Service Unavailable.

type: int

Static Constant.

HTTP Status-Code 503: Service Unavailable.

type: int
raw docstring

*-http-unsupported-typeclj

Static Constant.

HTTP Status-Code 415: Unsupported Media Type.

type: int

Static Constant.

HTTP Status-Code 415: Unsupported Media Type.

type: int
raw docstring

*-http-use-proxyclj

Static Constant.

HTTP Status-Code 305: Use Proxy.

type: int

Static Constant.

HTTP Status-Code 305: Use Proxy.

type: int
raw docstring

*-http-versionclj

Static Constant.

HTTP Status-Code 505: HTTP Version Not Supported.

type: int

Static Constant.

HTTP Status-Code 505: HTTP Version Not Supported.

type: int
raw docstring

*get-follow-redirects?clj

(*get-follow-redirects?)

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. - boolean

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. - `boolean`
raw docstring

*set-follow-redirectsclj

(*set-follow-redirects 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.

set - a boolean indicating whether or not to follow HTTP redirects. - boolean

throws: java.lang.SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation.

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.

set - a boolean indicating whether or not to follow HTTP redirects. - `boolean`

throws: java.lang.SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation.
raw docstring

disconnectclj

(disconnect this)

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.

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.
raw docstring

get-error-streamclj

(get-error-stream this)

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. - java.io.InputStream

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. - `java.io.InputStream`
raw docstring

get-header-fieldclj

(get-header-field this 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 method to iterate through all the headers in the message.

n - an index, where n>=0. - int

returns: the value of the nth header field, or null if the value does not exist. - java.lang.String

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 method to iterate through all
 the headers in the message.

n - an index, where n>=0. - `int`

returns: the value of the nth header field,
          or null if the value does not exist. - `java.lang.String`
raw docstring

get-header-field-dateclj

(get-header-field-date this name default)

Description copied from class: URLConnection

name - the name of the header field. - java.lang.String default - a default value. - long

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. - long

Description copied from class: URLConnection

name - the name of the header field. - `java.lang.String`
default - a default value. - `long`

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. - `long`
raw docstring

get-header-field-keyclj

(get-header-field-key this 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) returns the status line, but getHeaderFieldKey(0) returns null.

n - an index, where n >=0. - int

returns: the key for the nth header field, or null if the key does not exist. - java.lang.String

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) returns the status
 line, but getHeaderFieldKey(0) returns null.

n - an index, where n >=0. - `int`

returns: the key for the nth header field,
          or null if the key does not exist. - `java.lang.String`
raw docstring

get-instance-follow-redirects?clj

(get-instance-follow-redirects? this)

Returns the value of this HttpURLConnection's instanceFollowRedirects field.

returns: the value of this HttpURLConnection's instanceFollowRedirects field. - boolean

Returns the value of this HttpURLConnection's
 instanceFollowRedirects field.

returns: the value of this HttpURLConnection's
          instanceFollowRedirects field. - `boolean`
raw docstring

get-permissionclj

(get-permission this)

Returns a SocketPermission object representing the permission necessary to connect to the destination host and port.

returns: a SocketPermission object representing the permission necessary to connect to the destination host and port. - java.security.Permission

throws: java.io.IOException - if an error occurs while computing the permission.

Returns a SocketPermission object representing the
 permission necessary to connect to the destination host and port.

returns: a SocketPermission object representing the
         permission necessary to connect to the destination
         host and port. - `java.security.Permission`

throws: java.io.IOException - if an error occurs while computing the permission.
raw docstring

get-request-methodclj

(get-request-method this)

Get the request method.

returns: the HTTP request method - java.lang.String

Get the request method.

returns: the HTTP request method - `java.lang.String`
raw docstring

get-response-codeclj

(get-response-code this)

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 - int

throws: java.io.IOException - if an error occurred connecting to the server.

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 - `int`

throws: java.io.IOException - if an error occurred connecting to the server.
raw docstring

get-response-messageclj

(get-response-message this)

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 - java.lang.String

throws: java.io.IOException - if an error occurred connecting to the server.

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 - `java.lang.String`

throws: java.io.IOException - if an error occurred connecting to the server.
raw docstring

set-chunked-streaming-modeclj

(set-chunked-streaming-mode this 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.

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. - int

throws: java.lang.IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.

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.

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. - `int`

throws: java.lang.IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
raw docstring

set-fixed-length-streaming-modeclj

(set-fixed-length-streaming-mode this content-length)

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.

NOTE: setFixedLengthStreamingMode(long) is recommended instead of this method as it allows larger content lengths to be set.

content-length - The number of bytes which will be written to the OutputStream. - int

throws: java.lang.IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.

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.

 NOTE: setFixedLengthStreamingMode(long) is recommended
 instead of this method as it allows larger content lengths to be set.

content-length - The number of bytes which will be written to the OutputStream. - `int`

throws: java.lang.IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
raw docstring

set-instance-follow-redirectsclj

(set-instance-follow-redirects this follow-redirects)

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.

follow-redirects - a boolean indicating whether or not to follow HTTP redirects. - boolean

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.

follow-redirects - a boolean indicating whether or not to follow HTTP redirects. - `boolean`
raw docstring

set-request-methodclj

(set-request-method this method)

Set the method for the URL request, one of:

GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions. The default method is GET.

method - the HTTP method - java.lang.String

throws: java.net.ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.

Set the method for the URL request, one of:

  GET
  POST
  HEAD
  OPTIONS
  PUT
  DELETE
  TRACE
  are legal, subject to protocol restrictions.  The default
 method is GET.

method - the HTTP method - `java.lang.String`

throws: java.net.ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.
raw docstring

using-proxyclj

(using-proxy this)

Indicates if the connection is going through a proxy.

returns: a boolean indicating if the connection is using a proxy. - boolean

Indicates if the connection is going through a proxy.

returns: a boolean indicating if the connection is
 using a proxy. - `boolean`
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close