UTL_HTTP v11
The UTL_HTTP
package provides a way to use the HTTP or HTTPS protocol to retrieve information found at an URL. Advanced Server supports the following functions and procedures:
Function/Procedure | Return Type | Description |
---|---|---|
BEGIN_REQUEST(url, method, http_version) | UTL_HTTP.REQ | Initiates a new HTTP request. |
END_REQUEST(r IN OUT) | n/a | Ends an HTTP request before allowing it to complete. |
END_RESPONSE(r IN OUT) | n/a | Ends the HTTP response. |
GET_BODY_CHARSET | VARCHAR2 | Returns the default character set of the body of future HTTP requests. |
GET_BODY_CHARSET(charset OUT) | n/a | Returns the default character set of the body of future HTTP requests. |
GET_FOLLOW_REDIRECT(max_redirects OUT) | n/a | Current setting for the maximum number of redirections allowed. |
GET_HEADER(r IN OUT, n, name OUT, value OUT) | n/a | Returns the nth header of the HTTP response. |
GET_HEADER_BY_NAME(r IN OUT, name, value OUT, n) | n/a | Returns the HTTP response header for the specified name. |
GET_HEADER_COUNT(r IN OUT) | INTEGER | Returns the number of HTTP response headers. |
GET_RESPONSE(r IN OUT) | UTL_HTTP.RESP | Returns the HTTP response. |
GET_RESPONSE_ERROR_CHECK(enable OUT) | n/a | Returns whether or not response error check is set. |
GET_TRANSFER_TIMEOUT(timeout OUT) | n/a | Returns the transfer timeout setting for HTTP requests. |
READ_LINE(r IN OUT, data OUT, remove_crlf) | n/a | Returns the HTTP response body in text form until the end of line. |
READ_RAW(r IN OUT, data OUT, len) | n/a | Returns the HTTP response body in binary form for a specified number of bytes. |
READ_TEXT(r IN OUT, data OUT, len) | n/a | Returns the HTTP response body in text form for a specified number of characters. |
REQUEST(url) | VARCHAR2 | Returns the content of a web page. |
REQUEST_PIECES(url, max_pieces) | UTL_HTTP. HTML_PIECES | Returns a table of 2000-byte segments retrieved from an URL. |
SET_BODY_CHARSET(charset) | n/a | Sets the default character set of the body of future HTTP requests. |
SET_FOLLOW_REDIRECT(max_redirects) | n/a | Sets the maximum number of times to follow the redirect instruction. |
SET_FOLLOW_REDIRECT(r IN OUT, max_redirects) | n/a | Sets the maximum number of times to follow the redirect instruction for an individual request. |
SET_HEADER(r IN OUT, name, value) | n/a | Sets the HTTP request header. |
SET_RESPONSE_ERROR_CHECK(enable) | n/a | Determines whether or not HTTP 4xx and 5xx status codes are to be treated as errors. |
SET_TRANSFER_TIMEOUT(timeout) | n/a | Sets the default, transfer timeout value for HTTP requests. |
SET_TRANSFER_TIMEOUT(r IN OUT, timeout) | n/a | Sets the transfer timeout value for an individual HTTP request. |
WRITE_LINE(r IN OUT, data) | n/a | Writes CRLF terminated data to the HTTP request body in TEXT form. |
WRITE_RAW(r IN OUT, data) | n/a | Writes data to the HTTP request body in BINARY form. |
WRITE_TEXT(r IN OUT, data) | n/a | Writes data to the HTTP request body in TEXT form. |
Advanced Server's implementation of UTL_HTTP
is a partial implementation when compared to Oracle's version. Only those functions and procedures listed in the table above are supported.
Note
In Advanced Server, an HTTP 4xx
or HTTP 5xx
response produces a database error; in Oracle, this is configurable but FALSE
by default.
In Advanced Server, the UTL_HTTP
text interfaces expect the downloaded data to be in the database encoding. All currently-available interfaces are text interfaces. In Oracle, the encoding is detected from HTTP headers; in the absence of the header, the default is configurable and defaults to ISO-8859-1
.
Advanced Server ignores all cookies it receives.
The UTL_HTTP
exceptions that can be raised in Oracle are not recognized by Advanced Server. In addition, the error codes returned by Advanced Server are not the same as those returned by Oracle.
There are various public constants available with UTL_HTTP
. These are listed in the following tables.
The following table contains UTL_HTTP
public constants defining HTTP versions and port assignments.
HTTP VERSIONS | |
---|---|
HTTP_VERSION_1_0 | CONSTANT VARCHAR2(64) := 'HTTP/1.0'; |
HTTP_VERSION_1_1 | CONSTANT VARCHAR2(64) := 'HTTP/1.1'; |
STANDARD PORT ASSIGNMENTS | |
DEFAULT_HTTP_PORT | CONSTANT INTEGER := 80; |
DEFAULT_HTTPS_PORT | CONSTANT INTEGER := 443; |
The following table contains UTL_HTTP
public status code constants.
1XX INFORMATIONAL | |
---|---|
HTTP_CONTINUE | CONSTANT INTEGER := 100; |
HTTP_SWITCHING_PROTOCOLS | CONSTANT INTEGER := 101; |
HTTP_PROCESSING | CONSTANT INTEGER := 102; |
2XX SUCCESS | |
HTTP_OK | CONSTANT INTEGER := 200; |
HTTP_CREATED | CONSTANT INTEGER := 201; |
HTTP_ACCEPTED | CONSTANT INTEGER := 202; |
HTTP_NON_AUTHORITATIVE_INFO | CONSTANT INTEGER := 203; |
HTTP_NO_CONTENT | CONSTANT INTEGER := 204; |
HTTP_RESET_CONTENT | CONSTANT INTEGER := 205; |
HTTP_PARTIAL_CONTENT | CONSTANT INTEGER := 206; |
HTTP_MULTI_STATUS | CONSTANT INTEGER := 207; |
HTTP_ALREADY_REPORTED | CONSTANT INTEGER := 208; |
HTTP_IM_USED | CONSTANT INTEGER := 226; |
3XX REDIRECTION | |
HTTP_MULTIPLE_CHOICES | CONSTANT INTEGER := 300; |
HTTP_MOVED_PERMANENTLY | CONSTANT INTEGER := 301; |
HTTP_FOUND | CONSTANT INTEGER := 302; |
HTTP_SEE_OTHER | CONSTANT INTEGER := 303; |
HTTP_NOT_MODIFIED | CONSTANT INTEGER := 304; |
HTTP_USE_PROXY | CONSTANT INTEGER := 305; |
HTTP_SWITCH_PROXY | CONSTANT INTEGER := 306; |
HTTP_TEMPORARY_REDIRECT | CONSTANT INTEGER := 307; |
HTTP_PERMANENT_REDIRECT | CONSTANT INTEGER := 308; |
4XX CLIENT ERROR | |
---|---|
HTTP_BAD_REQUEST | CONSTANT INTEGER := 400; |
HTTP_UNAUTHORIZED | CONSTANT INTEGER := 401; |
HTTP_PAYMENT_REQUIRED | CONSTANT INTEGER := 402; |
HTTP_FORBIDDEN | CONSTANT INTEGER := 403; |
HTTP_NOT_FOUND | CONSTANT INTEGER := 404; |
HTTP_METHOD_NOT_ALLOWED | CONSTANT INTEGER := 405; |
HTTP_NOT_ACCEPTABLE | CONSTANT INTEGER := 406; |
HTTP_PROXY_AUTH_REQUIRED | CONSTANT INTEGER := 407; |
HTTP_REQUEST_TIME_OUT | CONSTANT INTEGER := 408; |
HTTP_CONFLICT | CONSTANT INTEGER := 409; |
HTTP_GONE | CONSTANT INTEGER := 410; |
HTTP_LENGTH_REQUIRED | CONSTANT INTEGER := 411; |
HTTP_PRECONDITION_FAILED | CONSTANT INTEGER := 412; |
HTTP_REQUEST_ENTITY_TOO_LARGE | CONSTANT INTEGER := 413; |
HTTP_REQUEST_URI_TOO_LARGE | CONSTANT INTEGER := 414; |
HTTP_UNSUPPORTED_MEDIA_TYPE | CONSTANT INTEGER := 415; |
HTTP_REQ_RANGE_NOT_SATISFIABLE | CONSTANT INTEGER := 416; |
HTTP_EXPECTATION_FAILED | CONSTANT INTEGER := 417; |
HTTP_I_AM_A_TEAPOT | CONSTANT INTEGER := 418; |
HTTP_AUTHENTICATION_TIME_OUT | CONSTANT INTEGER := 419; |
HTTP_ENHANCE_YOUR_CALM | CONSTANT INTEGER := 420; |
HTTP_UNPROCESSABLE_ENTITY | CONSTANT INTEGER := 422; |
HTTP_LOCKED | CONSTANT INTEGER := 423; |
HTTP_FAILED_DEPENDENCY | CONSTANT INTEGER := 424; |
HTTP_UNORDERED_COLLECTION | CONSTANT INTEGER := 425; |
HTTP_UPGRADE_REQUIRED | CONSTANT INTEGER := 426; |
HTTP_PRECONDITION_REQUIRED | CONSTANT INTEGER := 428; |
HTTP_TOO_MANY_REQUESTS | CONSTANT INTEGER := 429; |
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE | CONSTANT INTEGER := 431; |
HTTP_NO_RESPONSE | CONSTANT INTEGER := 444; |
HTTP_RETRY_WITH | CONSTANT INTEGER := 449; |
HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS | CONSTANT INTEGER := 450; |
HTTP_REDIRECT | CONSTANT INTEGER := 451; |
HTTP_REQUEST_HEADER_TOO_LARGE | CONSTANT INTEGER := 494; |
HTTP_CERT_ERROR | CONSTANT INTEGER := 495; |
HTTP_NO_CERT | CONSTANT INTEGER := 496; |
HTTP_HTTP_TO_HTTPS | CONSTANT INTEGER := 497; |
HTTP_CLIENT_CLOSED_REQUEST | CONSTANT INTEGER := 499; |
5XX SERVER ERROR | |
---|---|
HTTP_INTERNAL_SERVER_ERROR | CONSTANT INTEGER := 500; |
HTTP_NOT_IMPLEMENTED | CONSTANT INTEGER := 501; |
HTTP_BAD_GATEWAY | CONSTANT INTEGER := 502; |
HTTP_SERVICE_UNAVAILABLE | CONSTANT INTEGER := 503; |
HTTP_GATEWAY_TIME_OUT | CONSTANT INTEGER := 504; |
HTTP_VERSION_NOT_SUPPORTED | CONSTANT INTEGER := 505; |
HTTP_VARIANT_ALSO_NEGOTIATES | CONSTANT INTEGER := 506; |
HTTP_INSUFFICIENT_STORAGE | CONSTANT INTEGER := 507; |
HTTP_LOOP_DETECTED | CONSTANT INTEGER := 508; |
HTTP_BANDWIDTH_LIMIT_EXCEEDED | CONSTANT INTEGER := 509; |
HTTP_NOT_EXTENDED | CONSTANT INTEGER := 510; |
HTTP_NETWORK_AUTHENTICATION_REQUIRED | CONSTANT INTEGER := 511; |
HTTP_NETWORK_READ_TIME_OUT_ERROR | CONSTANT INTEGER := 598; |
HTTP_NETWORK_CONNECT_TIME_OUT_ERROR | CONSTANT INTEGER := 599; |
HTML_PIECES
The UTL_HTTP
package declares a type named HTML_PIECES
, which is a table of type VARCHAR2 (2000)
indexed by BINARY INTEGER
. A value of this type is returned by the REQUEST_PIECES
function.
REQ
The REQ
record type holds information about each HTTP request.
RESP
The RESP
record type holds information about the response from each HTTP request.
BEGIN_REQUEST
The BEGIN_REQUEST
function initiates a new HTTP request. A network connection is established to the web server with the specified URL. The signature is:
The BEGIN_REQUEST
function returns a record of type UTL_HTTP.REQ
.
Parameters
url
url
is the Uniform Resource Locator from which UTL_HTTP
will return content.
method
method
is the HTTP method to be used. The default is GET
.
http_version
http_version
is the HTTP protocol version sending the request. The specified values should be either HTTP/1.0
or HTTP/1.1
. The default is null in which case the latest HTTP protocol version supported by the UTL_HTTP
package is used which is 1.1.
END_REQUEST
The END_REQUEST
procedure terminates an HTTP request. Use the END_REQUEST
procedure to terminate an HTTP request without completing it and waiting for the response. The normal process is to begin the request, get the response, then close the response. The signature is:
Parameters
r
r
is the HTTP request record.
END_RESPONSE
The END_RESPONSE
procedure terminates the HTTP response. The END_RESPONSE
procedure completes the HTTP request and response. This is the normal method to end the request and response process. The signature is:
Parameters
r
r
is the HTTP
response record.
GET_BODY_CHARSET
The GET_BODY_CHARSET
program is available in the form of both a procedure and a function. A call to GET_BODY_CHARSET
returns the default character set of the body of future HTTP requests.
The procedure signature is: