Skip Headers

PL/SQL Packages and Types Reference
10g Release 1 (10.1)

Part Number B10802-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

156
UTL_HTTP

The UTL_HTTP package makes Hypertext Transfer Protocol (HTTP) callouts from SQL and PL/SQL. You can use it to access data on the Internet over HTTP.

When the package fetches data from a Web site using HTTPS, it requires Oracle Wallet Manager to set up an Oracle wallet. Non-HTTPS fetches do not require an Oracle wallet.

See Also:

This chapter contains the following topics:


Using UTL_HTTP


Overview

With UTL_HTTP, you can write PL/SQL programs that communicate with Web (HTTP) servers. UTL_HTTP also contains a function that can be used in SQL queries. The package also supports HTTP over the Secured Socket Layer protocol (SSL), also known as HTTPS, directly or through an HTTP proxy. Other Internet-related data-access protocols (such as the File Transfer Protocol (FTP) or the Gopher protocol) are also supported using an HTTP proxy server that supports those protocols.


Constants

Table 156-1 Constants
Constant and Syntax Purpose

HTTP_VERSION_1_0 CONSTANT VARCHAR2(10) := 'HTTP/1.0';

Denotes HTTP version 1.0 that can be used in the function begin_request.

HTTP_VERSION_1 CONSTANT VARCHAR2(10) := 'HTTP/1.1';

Denotes HTTP version 1.1 that can be used in the function begin_request.

DEFAULT_HTTP_PORT CONSTANT PLS_INTEGER := 80;

The default TCP/IP port (80) at which a Web server or proxy server listens

DEFAULT_HTTPS_PORT CONSTANT PLS_INTEGER := 443;

The default TCP/IP port (443) at which an HTTPS Web server listens

Table 156-2  HTTP 1.1 Status Codes:
Constant and Syntax

HTTP_VERSION_1_0 CONSTANT VARCHAR2(10) := 'HTTP/1.0';

HTTP_VERSION_1 CONSTANT VARCHAR2(10) := 'HTTP/1.1';

DEFAULT_HTTP_PORT CONSTANT PLS_INTEGER := 80;

DEFAULT_HTTPS_PORT CONSTANT PLS_INTEGER := 443;

The following denote all the HTTP 1.1 status codes:

HTTP_CONTINUE CONSTANT PLS_INTEGER := 100;

HTTP_SWITCHING_PROTOCOLS CONSTANT PLS_INTEGER := 101;

HTTP_OK CONSTANT PLS_INTEGER := 200;

HTTP_CREATED CONSTANT PLS_INTEGER := 201;

HTTP_ACCEPTED CONSTANT PLS_INTEGER := 202;

HTTP_NON_AUTHORITATIVE_INFO CONSTANT PLS_INTEGER := 203;

HTTP_NO_CONTENT CONSTANT PLS_INTEGER := 204;

HTTP_RESET_CONTENT CONSTANT PLS_INTEGER := 205;

HTTP_PARTIAL_CONTENT CONSTANT PLS_INTEGER := 206;

HTTP_MULTIPLE_CHOICES CONSTANT PLS_INTEGER := 300;

HTTP_MOVED_PERMANENTLY CONSTANT PLS_INTEGER := 301;

HTTP_FOUND CONSTANT PLS_INTEGER := 302;

HTTP_SEE_OTHER CONSTANT PLS_INTEGER := 303;

HTTP_NOT_MODIFIED CONSTANT PLS_INTEGER := 304;

HTTP_USE_PROXY CONSTANT PLS_INTEGER := 305;

HTTP_TEMPORARY_REDIRECT CONSTANT PLS_INTEGER := 307;

HTTP_BAD_REQUEST CONSTANT PLS_INTEGER := 400;

HTTP_UNAUTHORIZED CONSTANT PLS_INTEGER := 401;

HTTP_PAYMENT_REQUIRED CONSTANT PLS_INTEGER := 402;

HTTP_FORBIDDEN CONSTANT PLS_INTEGER := 403;

HTTP_NOT_FOUND CONSTANT PLS_INTEGER := 404;

HTTP_NOT_ACCEPTABLE CONSTANT PLS_INTEGER := 406;

HTTP_PROXY_AUTH_REQUIRED CONSTANT PLS_INTEGER := 407;

HTTP_REQUEST_TIME_OUT CONSTANT PLS_INTEGER := 408;

HTTP_CONFLICT CONSTANT PLS_INTEGER := 409;

HTTP_GONE CONSTANT PLS_INTEGER := 410;

HTTP_LENGTH_REQUIRED CONSTANT PLS_INTEGER := 411;

HTTP_PRECONDITION_FAILED CONSTANT PLS_INTEGER := 412;

HTTP_REQUEST_ENTITY_TOO_LARGE CONSTANT PLS_INTEGER := 413;

HTTP_REQUEST_URI_TOO_LARGE CONSTANT PLS_INTEGER := 414;

HTTP_UNSUPPORTED_MEDIA_TYPE CONSTANT PLS_INTEGER := 415;

HTTP_REQ_RANGE_NOT_SATISFIABLE CONSTANT PLS_INTEGER := 416;

HTTP_EXPECTATION_FAILED CONSTANT PLS_INTEGER := 417;

HTTP_NOT_IMPLEMENTED CONSTANT PLS_INTEGER := 501;

HTTP_BAD_GATEWAY CONSTANT PLS_INTEGER := 502;

HTTP_SERVICE_UNAVAILABLE CONSTANT PLS_INTEGER := 503;

HTTP_GATEWAY_TIME_OUT CONSTANT PLS_INTEGER := 504;

HTTP_VERSION_NOT_SUPPORTED CONSTANT PLS_INTEGER := 505;


Types

REQ Type

Use this PL/SQL record type to represent an HTTP request.

Syntax
TYPE req IS RECORD (
   url           VARCHAR2(32767),
   method        VARCHAR2(64),
   http_version  VARCHAR2(64));
Parameters
Table 156-3 REQ Type Parameters
Parameter Description

url

The URL of the HTTP request. It is set after the request is created by begin_request.

method

The method to be performed on the resource identified by the URL. It is set after the request is created by begin_request.

http_version

The HTTP protocol version used to send the request. It is set after the request is created by begin_request.

Usage Notes

The information returned in REQ from the interface begin_request is for read only. Changing the field values in the record has no effect on the request.

There are other fields in REQ record type whose names begin with the prefix private_. The fields are private and are intended for use by implementation of the UTL_HTTP package. You should not modify the fields.

RESP Type

This PL/SQL record type is used to represent an HTTP response.

Syntax
TYPE resp IS RECORD (
   status_code    PLS_INTEGER,
   reason_phrase  VARCHAR2(256),
   http_version   VARCHAR2(64));
Parameters
Table 156-4 RESP Type Parameters
Parameter Description

status_code

The status code returned by the Web server. It is a 3-digit integer that indicates the results of the HTTP request as handled by the Web server. It is set after the response is processed by get_response.

reason_phrase

The short textual message returned by the Web server that describe the status code. It gives a brief description of the results of the HTTP request as handled by the Web server. It is set after the response is processed by get_response.

http_version

The HTTP protocol version used in the HTTP response. It is set after the response is processed by get_response.

Usage Notes

The information returned in RESP from the interface get_response is read-only. There are other fields in the RESP record type whose names begin with the prefix private_. The fields are private and are intended for use by implementation of the UTL_HTTP package. You should not modify the fields.

COOKIE and COOKIE_TABLE Types

The COOKIE type is the PL/SQL record type that represents an HTTP cookie. The COOKIE_TABLE type is a PL/SQL index-by-table type that represents a collection of HTTP cookies.

Syntax
TYPE cookie IS RECORD (
   name  VARCHAR2(256),
   value  VARCHAR2(1024),
   domain  VARCHAR2(256),
   expire  TIMESTAMP WITH TIME ZONE,
   path  VARCHAR2(1024),
   secure  BOOLEAN,
   version  PLS_INTEGER,
   comment  VARCHAR2(1024));

TYPE cookie_table IS TABLE OF cookie INDEX BY binary_integer;
Fields of COOKIE Record Type

Table 156-5 shows the fields for the COOKIE and COOKIE_TABLE record types.

Table 156-5 Fields of COOKIE and COOKIE_TABLE Type
Field Description

name

The name of the HTTP cookie

value

The value of the cookie

domain

The domain for which the cookie is valid

expire

The time by which the cookie will expire

path

The subset of URLs to which the cookie applies

secure

Should the cookie be returned to the Web server using secured means only.

version

The version of the HTTP cookie specification the cookie conforms. This field is NULL for Netscape cookies.

comment

The comment that describes the intended use of the cookie. This field is NULL for Netscape cookies.

Usage Notes

PL/SQL programs do not usually examine or change the cookie information stored in the UTL_HTTP package. The cookies are maintained by the package transparently. They are maintained inside the UTL_HTTP package, and they last for the duration of the database session only. PL/SQL applications that require cookies to be maintained beyond the lifetime of a database session can read the cookies using get_cookies, store them persistently in a database table, and re-store the cookies back in the package using add_cookies in the next database session. All the fields in the cookie record, except for the comment field, must be stored. Do not alter the cookie information, which can result in an application error in the Web server or compromise the security of the PL/SQL and the Web server applications. See "Retrieving and Restoring Cookies".

CONNECTION Type

Use the PL/SQL record type to represent the remote hosts and TCP/IP ports of a network connection that is kept persistent after an HTTP request is completed, according to the HTTP 1.1 protocol specification. The persistent network connection may be reused by a subsequent HTTP request to the same host and port. The subsequent HTTP request may be completed faster because the network connection latency is avoided. connection_table is a PL/SQL table of connection.

For a direct HTTP persistent connection to a Web server, the host and port fields contain the host name and TCP/IP port number of the Web server. The proxy_host and proxy_port fields are not set. For an HTTP persistent connection that was previously used to connect to a Web server using a proxy, the proxy_host and proxy_port fields contain the host name and TCP/IP port number of the proxy server. The host and port fields are not set, which indicates that the persistent connection, while connected to a proxy server, is not bound to any particular target Web server. An HTTP persistent connection to a proxy server can be used to access any target Web server that is using a proxy.

The ssl field indicates if Secured Socket Layer (SSL) is being used in an HTTP persistent connection. An HTTPS request is an HTTP request made over SSL. For an HTTPS (SSL) persistent connection connected using a proxy, the host and port fields contain the host name and TCP/IP port number of the target HTTPS Web server and the fields will always be set. An HTTPS persistent connection to an HTTPS Web server using a proxy server can only be reused to make another request to the same target Web server.

Syntax
TYPE connection IS RECORD (
   host  VARCHAR2(256),
   port  PLS_INTEGER,
   proxy_host  VARCHAR2(256),
   proxy_port  PLS_INTEGER,
   ssl  BOOLEAN);

TYPE connection_table IS TABLE OF connection INDEX BY BINARY_INTEGER;

Operational Notes

Operational Flow

The UTL_HTTP package provides access to the HTTP protocol. The interfaces must be called in the order shown in Figure 156-1, or an exception will be raised.

Figure 156-1 Flow of the Core UTL_HTTP Package

Text description of arpls006.gif follows

Text description of the illustration arpls006.gif

The following can be called at any time:

Simple HTTP Fetches

REQUEST and REQUEST_PIECES take a string uniform resource locator (URL), contact that site, and return the data (typically HTML) obtained from that site.

You should not expect REQUEST or REQUEST_PIECES to succeed in contacting a URL unless you can contact that URL by using a browser on the same machine (and with the same privileges, environment variables, and so on.)

If REQUEST or REQUEST_PIECES fails (for example, if it raises an exception, or if it returns an HTML-formatted error message, but you believe that the URL argument is correct), then try contacting that same URL with a browser to verify network availability from your machine. You may have a proxy server set in your browser that needs to be set with each REQUEST or REQUEST_PIECES call using the optional proxy parameter.


Note:

UTL_HTTP can also use environment variables to specify its proxy behavior. For example, on UNIX, setting the environment variable http_proxy to a URL uses that service as the proxy server for HTTP requests. Setting the environment variable no_proxy to a domain name does not use the HTTP proxy server for URLs in that domain. When the UTL_HTTP package is executed in the Oracle database server, the environment variables are the ones that are set when the database instance is started.


See Also:

Simple HTTP Fetches in a Single Call Subprograms

Session Settings

Session settings manipulate the configuration and default behavior of UTL_HTTP when HTTP requests are executed within a database user session. When a request is created, it inherits the default settings of the HTTP cookie support, follow-redirect, body character set, persistent-connection support, and transfer timeout of the current session. Those settings can be changed later by calling the request interface. When a response is created for a request, it inherits those settings from the request. Only the body character set can be changed later by calling the response interface.

See Also:

Session Settings Subprograms

HTTP Requests

The HTTP Requests group of subprograms begin an HTTP request, manipulate attributes, and send the request information to the Web server. When a request is created, it inherits the default settings of the HTTP cookie support, follow-redirect, body character set, persistent-connection support, and transfer timeout of the current session. The settings can be changed by calling the request interface.

See Also:

HTTP Requests Subprograms

HTTP Responses

The HTTP Responses group of subprograms manipulate an HTTP response obtained from GET_RESPONSE and receive response information from the Web server. When a response is created for a request, it inherits settings of the HTTP cookie support, follow-redirect, body character set, persistent-connection support, and transfer timeout from the request. Only the body character set can be changed by calling the response interface.

See Also:

HTTP Responses Subprograms

HTTP Cookies

The UTL_HTTP package provides subprograms to manipulate HTTP cookies.

See Also:

HTTP Cookies Subprograms

HTTP Persistent Connections

The UTL_HTTP package provides subprograms to manipulate persistent connections.

See Also:

HTTP Persistent Connections Subprograms

Error Conditions

The UTL_HTTP package provides subprograms to retrieve error information.

See Also:

Error Conditions Subprograms


Exceptions

Table 156-6 lists the exceptions that the UTL_HTTP package interface can raise. By default, UTL_HTTP raises the exception request_failed when a request fails to execute. If the package is set to raise a detailed exception by set_detailed_excp_support, the rest of the exceptions will be raised directly (except for the exception end_of_body, which will be raised by read_text, read_line, and read_raw regardless of the setting).

Table 156-6  UTL_HTTP Exceptions
Exception Error Code Reason Where Raised

request_failed

29273

The request fails to executes

Any HTTP request or response interface when detailed_exception is disabled

bad_argument

29261

The argument passed to the interface is bad

Any HTTP request or response interface when detailed_exception is enabled

bad_url

29262

The requested URL is badly formed

begin_request, when detailed_exception is enabled

protocol_error

29263

An HTTP protocol error occurs when communicating with the Web server

set_header, get_response, read_raw, read_text, and read_line, when detailed_exception is enabled

unknown_scheme

29264

The scheme of the requested URL is unknown

begin_request and get_response, when detailed_exception is enabled

header_not_found

29265

The header is not found

get_header, get_header_by_name, when detailed_exception is enabled

end_of_body

29266

The end of HTTP response body is reached

read_raw, read_text, and read_line, when detailed_exception is enabled

illegal_call

29267

The call to UTL_HTTP is illegal at the current state of the HTTP request

set_header, set_authentication, and set_persistent_conn_support, when detailed_exception is enabled

http_client_error

29268

From get_response, the response status code indicates that a client error has occurred (status code in 4xx range). Or from begin_request, the HTTP proxy returns a status code in the 4xx range when making an HTTPS request through the proxy.

get_response, begin_request when detailed_exception is enabled

http_server_error

29269

From get_response, the response status code indicates that a client error has occurred (status code in 5xx range). Or from begin_request, the HTTP proxy returns a status code in the 5xx range when making an HTTPS request through the proxy.

get_response, begin_request when detailed_exception is enabled

too_many_requests

29270

Too many requests or responses are open

begin_request, when detailed_exception is enabled

partial_multibyte_exception

29275

No complete character is read and a partial multibyte character is found at the end of the response body

read_text and read_line, when detailed_exception is enabled

transfer_timeout

29276

No data is read and a read timeout occurred

read_text and read_line, when detailed_exception is enabled


NOTE:

The partial_multibyte_char and transfer_timeout exceptions are duplicates of the same exceptions defined in UTL_TCP. They are defined in this package so that the use of this package does not require the knowledge of the UTL_TCP. As those exceptions are duplicates, an exception handle that catches the partial_multibyte_char and transfer_timeout exceptions in this package also catch the exceptions in the UTL_TCP.


For REQUEST and REQUEST_PIECES, the request_failed exception is raised when any exception occurs and detailed_exception is disabled.


Examples

The following examples demonstrate how to use UTL_HTTP.

General Usage

SET serveroutput ON SIZE 40000
  
DECLARE
  req   utl_http.req;
  resp  utl_http.resp;
  value VARCHAR2(1024);
BEGIN

  utl_http.set_proxy('proxy.my-company.com', 'corp.my-company.com');

  req := utl_http.begin_request('http://www-hr.corp.my-company.com');
  utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
  resp := utl_http.get_response(req);
  LOOP
    utl_http.read_line(resp, value, TRUE);
    dbms_output.put_line(value);
  END LOOP;
  utl_http.end_response(resp);
EXCEPTION
  WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
END;

Retrieving HTTP Response Headers

SET serveroutput ON SIZE 40000
  
DECLARE
  req   utl_http.req;
  resp  utl_http.resp;
  name  VARCHAR2(256);
  value VARCHAR2(1024);
BEGIN

  utl_http.set_proxy('proxy.my-company.com', 'corp.my-company.com');
 
  req := utl_http.begin_request('http://www-hr.corp.my-company.com');
  utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
  resp := utl_http.get_response(req);

  dbms_output.put_line('HTTP response status code: ' || resp.status_code);
  dbms_output.put_line('HTTP response reason phrase: ' || resp.reason_phrase);

  FOR i IN 1..utl_http.get_header_count(resp) LOOP
    utl_http.get_header(resp, i, name, value);
    dbms_output.put_line(name || ': ' || value);
  END LOOP;
  utl_http.end_response(resp);
END;

Handling HTTP Authentication

SET serveroutput ON SIZE 40000
  
CREATE OR REPLACE PROCEDURE get_page (url      IN VARCHAR2,
                                      username IN VARCHAR2 DEFAULT NULL,
                                      password IN VARCHAR2 DEFAULT NULL,
                                      realm    IN VARCHAR2 DEFAULT NULL) AS
  req       utl_http.req;
  resp      utl_http.resp;
  my_scheme VARCHAR2(256);
  my_realm  VARCHAR2(256);
  my_proxy  BOOLEAN;
BEGIN

  -- Turn off checking of status code. We will check it by ourselves.
  utl_http.http_response_error_check(FALSE);

  req := utl_http.begin_request(url);
  IF (username IS NOT NULL) THEN
    utl_http.set_authentication(req, username, password); -- Use HTTP Basic 
Authen. Scheme
  END IF;

  resp := utl_http.get_response(req);
  IF (resp.status_code = utl_http.HTTP_UNAUTHORIZED) THEN
    utl_http.get_authentication(resp, my_scheme, my_realm, my_proxy);
    IF (my_proxy) THEN
       dbms_output.put_line('Web proxy server is protected.');
       dbms_output.put('Please supplied the required ' || my_scheme || ' 
authentication username/password for realm ' || my_realm || ' for the proxy 
server.');
    ELSE
      dbms_output.put_line('Web page ' || url || ' is protected.');
      dbms_output.put('Please supplied the required ' || my_scheme || ' 
authentication username/password for realm ' || my_realm || ' for the Web 
page.');
    END IF;
    utl_http.end_response(resp);
    RETURN;
  END IF;

  FOR i IN 1..utl_http.get_header_count(resp) LOOP
    utl_http.get_header(resp, i, name, value);
    dbms_output.put_line(name || ': ' || value);
  END LOOP;
  utl_http.end_response(resp);

END;

Retrieving and Restoring Cookies

CREATE TABLE my_cookies (
    session_id  INTEGER,
    name        VARCHAR2(256),
    value       VARCHAR2(1024),
    domain      VARCHAR2(256),
    expire      DATE,
    path        VARCHAR2(1024),
    secure      VARCHAR2(1),
    version     INTEGER
);

CREATE SEQUENCE session_id;

SET serveroutput ON SIZE 40000

REM Retrieve cookies from UTL_HTTP

CREATE OR REPLACE FUNCTION save_cookies RETURN PLS_INTEGER AS
  cookies        utl_http.cookie_table;
  my_session_id  PLS_INTEGER;
  secure         VARCHAR2(1);
BEGIN

  /* assume that some cookies have been set in previous HTTP requests. */

  utl_http.get_cookies(cookies);
  select session_id.nextval into my_session_id from dual;

  FOR i in 1..cookies.count LOOP
    IF (cookies(i).secure) THEN
      secure := 'Y';
    ELSE
      secure := 'N';
    END IF;
    insert into my_cookies
    values (my_session_id, cookies(i).name, cookies(i).value,
cookies(i).domain,
           cookies(i).expire, cookies(i).path, secure, cookies(i).version);
  END LOOP;

  RETURN my_session_id;

END;
/

REM Retrieve cookies from UTL_HTTP

CREATE OR REPLACE PROCEDURE restore_cookies (this_session_id IN PLS_INTEGER)
AS
  cookies        utl_http.cookie_table;
  cookie         utl_http.cookie;
  i              PLS_INTEGER := 0;
  CURSOR c (c_session_id PLS_INTEGER) IS
    SELECT * FROM my_cookies WHERE session_id = c_session_id;
BEGIN

  FOR r IN c(this_session_id) LOOP
    i := i + 1;
    cookie.name   := r.name;
    cookie.value  := r.value;
    cookie.domain := r.domain;
    cookie.expire := r.expire;
    cookie.path   := r.path;
    IF (r.secure = 'Y') THEN
      cookie.secure := TRUE;
    ELSE
      cookie.secure := FALSE;
    END IF;
    cookie.version := r.version;
    cookies(i) := cookie;
  END LOOP;

  utl_http.clear_cookies;
  utl_http.add_cookies(cookies);

END;
/

Subprogram Groups


Simple HTTP Fetches in a Single Call Subprograms

Table 156-7  UTL_HTTP Subprograms--Simple HTTP Fetches in a Single Call
Subprogram Description

REQUEST Function

Returns up to the first 2000 bytes of the data retrieved from the given URL. This function can be used directly in SQL queries

REQUEST_PIECES Function

Returns a PL/SQL table of 2000-byte pieces of the data retrieved from the given URL


Session Settings Subprograms

Table 156-8  UTL_HTTP Subprograms--Session Settings
Subprogram Description

GET_BODY_CHARSET Procedure

Retrieves the default character set of the body of all future HTTP requests

GET_COOKIE_SUPPORT Procedure

Retrieves the current cookie support settings

GET_DETAILED_EXCP_SUPPORT Procedure

Checks if the UTL_HTTP package will raise a detailed exception or not

GET_FOLLOW_REDIRECT Procedure

Retrieves the follow-redirect setting in the current session

GET_PERSISTENT_CONN_SUPPORT Procedure

Checks if the persistent connection support is enabled and gets the maximum number of persistent connections in the current session

GET_PROXY Procedure

Retrieves the current proxy settings

GET_RESPONSE_ERROR_CHECK Procedure

Checks if the response error check is set or not

GET_TRANSFER_TIMEOUT Procedure

Retrieves the current network transfer timeout value

SET_BODY_CHARSET Procedures

Sets the default character set of the body of all future HTTP requests when the media type is text and the character set is not specified in the Content-Type header

SET_COOKIE_SUPPORT Procedures

Sets whether or not future HTTP requests will support HTTP cookies; sets the maximum number of cookies maintained in the current database user session

SET_DETAILED_EXCP_SUPPORT Procedure

Sets the UTL_HTTP package to raise a detailed exception

SET_FOLLOW_REDIRECT Procedures

Sets the maximum number of times UTL_HTTP follows the HTTP redirect instruction in the HTTP responses to future requests in the get_response function

SET_PERSISTENT_CONN_SUPPORT Procedure

Sets whether or not future HTTP requests will support the HTTP 1.1 persistent connection; sets the maximum number of persistent connections maintained in the current database user session

SET_PROXY Procedure

Sets the proxy to be used for requests of HTTP or other protocols

SET_RESPONSE_ERROR_CHECK Procedure

Sets whether or not get_response raises an exception when the Web server returns a status code that indicates an error--a status code in the 4xx or 5xx ranges

SET_TRANSFER_TIMEOUT Procedure

Sets the timeout value for UTL_HTTP to read the HTTP response from the Web server or proxy server

SET_WALLET Procedure

Sets the Oracle Wallet used for all HTTP requests over Secured Socket Layer (SSL), that is, HTTPS


HTTP Requests Subprograms

Table 156-9  UTL_HTTP Subprograms--HTTP Requests
Subprogram Description

BEGIN_REQUEST Function

Begins a new HTTP request. UTL_HTTP establishes the network connection to the target Web server or the proxy server and sends the HTTP request line.

END_REQUEST Procedure

Ends the HTTP request.

SET_HEADER Procedure

Sets an HTTP request header. The request header is sent to the Web server as soon as it is set.

SET_AUTHENTICATION Procedure

Sets HTTP authentication information in the HTTP request header. The Web server needs this information to authorize the request.

SET_BODY_CHARSET Procedures

Sets the character set of the request body when the media type is text but the character set is not specified in the Content-Type header.

SET_COOKIE_SUPPORT Procedures

Enables or disables support for the HTTP cookies in the request.

SET_FOLLOW_REDIRECT Procedures

Sets the maximum number of times UTL_HTTP follows the HTTP redirect instruction in the HTTP response to this request in the GET_RESPONSE Function.

SET_PERSISTENT_CONN_SUPPORT Procedure

Enables or disables support for the HTTP 1.1 persistent-connection in the request.

WRITE_LINE Procedure

Writes a text line in the HTTP request body and ends the line with new-line characters (CRLF as defined in UTL_TCP).

WRITE_RAW Procedure

Writes some binary data in the HTTP request body.

WRITE_TEXT Procedure

Writes some text data in the HTTP request body.


HTTP Responses Subprograms

Table 156-10  UTL_HTTP Subprograms--HTTP Responses
Subprogram Description

END_RESPONSE Procedure

Ends the HTTP response. It completes the HTTP request and response.

GET_AUTHENTICATION Procedure

Retrieves the HTTP authentication information needed for the request to be accepted by the Web server as indicated in the HTTP response header.

GET_HEADER Procedure

Returns the nth HTTP response header name and value returned in the response.

GET_HEADER_BY_NAME Procedure

Returns the HTTP response header value returned in the response given the name of the header.

GET_HEADER_COUNT Function

Returns the number of HTTP response headers returned in the response.

GET_RESPONSE Function

Reads the HTTP response. When the function returns, the status line and the HTTP response headers have been read and processed.

READ_LINE Procedure

Reads the HTTP response body in text form until the end of line is reached and returns the output in the caller-supplied buffer.

READ_RAW Procedure

Reads the HTTP response body in binary form and returns the output in the caller-supplied buffer.

READ_TEXT Procedure

Reads the HTTP response body in text form and returns the output in the caller-supplied buffer.

SET_BODY_CHARSET Procedures

Sets the character set of the response body when the media type is "text" but the character set is not specified in the "Content-Type" header.


HTTP Cookies Subprograms

Table 156-11  UTL_HTTP Subprograms--HTTP Cookies
Subprogram Description

ADD_COOKIES Procedure

Adds the cookies maintained by UTL_HTTP.

CLEAR_COOKIES Procedure

Clears all cookies maintained by the UTL_HTTP package.

GET_COOKIE_COUNT Function

Returns the number of cookies currently maintained by the UTL_HTTP package set by all Web servers.

GET_COOKIES Function

Returns all the cookies currently maintained by the UTL_HTTP package set by all Web servers.


HTTP Persistent Connections Subprograms

Table 156-12  UTL_HTTP Subprograms--HTTP Persistent Connections
Subprogram Description

CLOSE_PERSISTENT_CONN Procedure

Closes an HTTP persistent connection maintained by the UTL_HTTP package in the current database session.

CLOSE_PERSISTENT_CONNS Procedure

Closes a group of HTTP persistent connections maintained by the UTL_HTTP package in the current database session.

GET_PERSISTENT_CONN_COUNT Function

Returns the number of network connections currently kept persistent by the UTL_HTTP package to the Web servers.

GET_PERSISTENT_CONNS Procedure

Returns all the network connections currently kept persistent by the UTL_HTTP package to the Web servers.


Error Conditions Subprograms

Table 156-13  UTL_HTTP Subprograms--Error Conditions
Subprogram Description

GET_DETAILED_SQLCODE Function

Retrieves the detailed SQLCODE of the last exception raised.

GET_DETAILED_SQLERRM Function

Retrieves the detailed SQLERRM of the last exception raised.


Summary of UTL_HTTP Subprograms

Table 156-14  UTL_HTTP Package Subprograms
Subprogram Description

ADD_COOKIES Procedure

Adds the cookies maintained by UTL_HTTP (see HTTP Cookies and HTTP Cookies Subprograms)

BEGIN_REQUEST Function

Begins a new HTTP request. UTL_HTTP establishes the network connection to the target Web server or the proxy server and sends the HTTP request line (see HTTP Requests and HTTP Requests Subprograms)

CLEAR_COOKIES Procedure

Clears all cookies maintained by the UTL_HTTP package (see HTTP Cookies and HTTP Cookies Subprograms)

CLOSE_PERSISTENT_CONN Procedure

Closes an HTTP persistent connection maintained by the UTL_HTTP package in the current database session (see HTTP Persistent Connections and HTTP Persistent Connections Subprograms)

CLOSE_PERSISTENT_CONNS Procedure

Closes a group of HTTP persistent connections maintained by the UTL_HTTP package in the current database session (see HTTP Persistent Connections and HTTP Persistent Connections Subprograms)

END_REQUEST Procedure

Ends the HTTP request (see HTTP Requests and HTTP Requests Subprograms)

END_RESPONSE Procedure

Ends the HTTP response. It completes the HTTP request and response (see HTTP Responses and HTTP Responses Subprograms)

GET_AUTHENTICATION Procedure

Retrieves the HTTP authentication information needed for the request to be accepted by the Web server as indicated in the HTTP response header (see HTTP Responses and HTTP Responses Subprograms)

GET_BODY_CHARSET Procedure

Retrieves the default character set of the body of all future HTTP requests (see Session Settings and Session Settings Subprograms)

GET_COOKIE_COUNT Function

Returns the number of cookies currently maintained by the UTL_HTTP package set by all Web servers (see HTTP Cookies and HTTP Cookies Subprograms)

GET_COOKIE_SUPPORT Procedure

Retrieves the current cookie support settings (see Session Settings and Session Settings Subprograms)

GET_COOKIES Function

Returns all the cookies currently maintained by the UTL_HTTP package set by all Web servers (see HTTP Cookies and HTTP Cookies Subprograms)

GET_DETAILED_EXCP_SUPPORT Procedure

Checks if the UTL_HTTP package will raise a detailed exception or not (see Session Settings and Session Settings Subprograms)

GET_DETAILED_SQLCODE Function

Retrieves the detailed SQLCODE of the last exception raised (see Error Conditions and Error Conditions Subprograms)

GET_DETAILED_SQLERRM Function

Retrieves the detailed SQLERRM of the last exception raised (see Error Conditions and Error Conditions Subprograms)

GET_FOLLOW_REDIRECT Procedure

Retrieves the follow-redirect setting in the current session (see Session Settings and Session Settings Subprograms)

GET_HEADER Procedure

Returns the nth HTTP response header name and value returned in the response (see HTTP Responses and HTTP Responses Subprograms)

GET_HEADER_BY_NAME Procedure

Returns the HTTP response header value returned in the response given the name of the header (see HTTP Responses and HTTP Responses Subprograms)

GET_HEADER_COUNT Function

Returns the number of HTTP response headers returned in the response (see HTTP Responses and HTTP Responses Subprograms)

GET_PERSISTENT_CONN_COUNT Function

Returns the number of network connections currently kept persistent by the UTL_HTTP package to the Web servers (see HTTP Persistent Connections and HTTP Persistent Connections Subprograms)

GET_PERSISTENT_CONN_SUPPORT Procedure

Sees whether or not future HTTP requests will support the HTTP 1.1 persistent connection; sets the maximum number of persistent connections maintained in the current database user session (see Session Settings and Session Settings Subprograms)

GET_PERSISTENT_CONN_SUPPORT Procedure

Checks if the persistent connection support is enabled and gets the maximum number of persistent connections in the current session (see Session Settings and Session Settings Subprograms)

GET_PERSISTENT_CONNS Procedure

Returns all the network connections currently kept persistent by the UTL_HTTP package to the Web servers (see HTTP Persistent Connections and HTTP Persistent Connections Subprograms)

GET_PROXY Procedure

Retrieves the current proxy settings (see Session Settings and Session Settings Subprograms)

GET_RESPONSE Function

Reads the HTTP response. When the function returns, the status line and the HTTP response headers have been read and processed (see HTTP Responses and HTTP Responses Subprograms)

GET_RESPONSE_ERROR_CHECK Procedure

Checks if the response error check is set or no (see Session Settings and Session Settings Subprograms)t

GET_TRANSFER_TIMEOUT Procedure

Retrieves the current network transfer timeout value (see Session Settings and Session Settings Subprograms)

READ_LINE Procedure

Reads the HTTP response body in text form until the end of line is reached and returns the output in the caller-supplied buffer (see HTTP Responses and HTTP Responses Subprograms)

READ_RAW Procedure

Reads the HTTP response body in binary form and returns the output in the caller-supplied buffer (see HTTP Responses and HTTP Responses Subprograms)

READ_TEXT Procedure

Reads the HTTP response body in text form and returns the output in the caller-supplied buffer (see HTTP Responses and HTTP Responses Subprograms)

REQUEST Function

Returns up to the first 2000 bytes of the data retrieved from the given URL. This function can be used directly in SQL queries (see Simple HTTP Fetches and Simple HTTP Fetches in a Single Call Subprograms)

REQUEST_PIECES Function

Returns a PL/SQL table of 2000-byte pieces of the data retrieved from the given URL (see Simple HTTP Fetches and Simple HTTP Fetches in a Single Call Subprograms)

SET_AUTHENTICATION Procedure

Sets HTTP authentication information in the HTTP request header. The Web server needs this information to authorize the request (see HTTP Requests and HTTP Requests Subprograms)

SET_BODY_CHARSET Procedures

Sets the default character set of the body of all future HTTP requests when the media type is text and the character set is not specified in the Content-Type header (see Session Settings and Session Settings Subprograms)

SET_BODY_CHARSET Procedures

Sets the character set of the request body when the media type is text but the character set is not specified in the Content-Type header (see HTTP Requests and HTTP Requests Subprograms)

SET_BODY_CHARSET Procedures

Sets the character set of the response body when the media type is "text" but the character set is not specified in the "Content-Type" header (see HTTP Responses, HTTP Responses Subprograms, Session Settings and Session Settings Subprograms)

SET_COOKIE_SUPPORT Procedures

Enables or disables support for the HTTP cookies in the request (see HTTP Requests and HTTP Requests Subprograms)

SET_DETAILED_EXCP_SUPPORT Procedure

Sets whether or not future HTTP requests will support HTTP cookies; sets the maximum number of cookies maintained in the current database user session (see Session Settings and Session Settings Subprograms)

SET_DETAILED_EXCP_SUPPORT Procedure

Sets the UTL_HTTP package to raise a detailed exception (see Session Settings and Session Settings Subprograms)

SET_FOLLOW_REDIRECT Procedures

Sets the maximum number of times UTL_HTTP follows the HTTP redirect instruction in the HTTP response to this request in the GET_RESPONSE function (see HTTP Requests and HTTP Requests Subprograms)

SET_HEADER Procedure

Sets the maximum number of times UTL_HTTP follows the HTTP redirect instruction in the HTTP responses to future requests in the get_response function (see Session Settings and Session Settings Subprograms)

SET_HEADER Procedure

Sets an HTTP request header. The request header is sent to the Web server as soon as it is set (see HTTP Requests and HTTP Requests Subprograms)

SET_PERSISTENT_CONN_SUPPORT Procedure

Enables or disables support for the HTTP 1.1 persistent-connection in the request (see HTTP Requests and HTTP Requests Subprograms)

SET_PROXY Procedure

Sets the proxy to be used for requests of HTTP or other protocols (see Session Settings and Session Settings Subprograms)

SET_RESPONSE_ERROR_CHECK Procedure

Sets whether or not get_response raises an exception when the Web server returns a status code that indicates an error--a status code in the 4xx or 5xx ranges (see Session Settings and Session Settings Subprograms)

SET_TRANSFER_TIMEOUT Procedure

Sets the timeout value for UTL_HTTP to read the HTTP response from the Web server or proxy server (see Session Settings and Session Settings Subprograms)

SET_WALLET Procedure

Sets the Oracle Wallet used for all HTTP requests over Secured Socket Layer (SSL), that is, HTTPS (see Session Settings and Session Settings Subprograms)

WRITE_LINE Procedure

Writes a text line in the HTTP request body and ends the line with new-line characters (CRLF as defined in UTL_TCP) (see HTTP Requests and HTTP Requests Subprograms)

WRITE_RAW Procedure

Writes some binary data in the HTTP request body (see HTTP Requests and HTTP Requests Subprograms)

WRITE_TEXT Procedure

Writes some text data in the HTTP request body (see HTTP Requests and HTTP Requests Subprograms)


ADD_COOKIES Procedure

This procedure adds the cookies maintained by UTL_HTTP.

See Also:

HTTP Cookies and HTTP Cookies Subprograms

Syntax

UTL_HTTP.ADD_COOKIES (
   cookies  IN cookie_table);

Parameters

Table 156-15 ADD_COOKIES Procedure Parameters
Parameter Description

cookies

The cookies to be added.

Usage Notes

The cookies that the package currently maintains are not cleared before new cookies are added.


BEGIN_REQUEST Function

This functions begins a new HTTP request. UTL_HTTP establishes the network connection to the target Web server or the proxy server and sends the HTTP request line. The PL/SQL program continues the request by calling some other interface to complete the request. The URL may contain the username and password needed to authenticate the request to the server. The format is

scheme://[user[:password]@]host[:port]/[...]

See Also:

HTTP Requests and HTTP Requests Subprograms

Syntax

UTL_HTTP.BEGIN_REQUEST (
   url           IN VARCHAR2,
   method        IN VARCHAR2 DEFAULT 'GET',
   http_version  IN VARCHAR2 DEFAULT NULL)
RETURN req;

Parameters

Table 156-16 BEGIN_REQUEST Function Parameters
Parameter Description

url

The URL of the HTTP request.

method

The method performed on the resource identified by the URL.

http_version

The HTTP protocol version that sends the request. The format of the protocol version is HTTP/major-version.minor-version, where major-version and minor-version are positive numbers. If this parameter is set to NULL, UTL_HTTP uses the latest HTTP protocol version that it supports to send the request. The latest version that the package supports is 1.1 and it can be upgraded to a later version. The default is NULL.

Usage Notes

The URL passed as an argument to this function is not examined for illegal characters, such as spaces, according to URL specification RFC 2396. You should escape those characters with the UTL_URL package to return illegal and reserved characters. URLs should consist of US-ASCII characters only. See Chapter 166, "UTL_URL" for a list of legal characters in URLs. Note that URLs should consist of US-ASCII characters only. The use of non-US-ASCII characters in a URL is generally unsafe.

An Oracle wallet must be set before accessing Web servers over HTTPS. See the set_wallet procedure on how to set up an Oracle wallet.


CLEAR_COOKIES Procedure

This procedure clears all cookies maintained by the UTL_HTTP package.

See Also:

HTTP Cookies and HTTP Cookies Subprograms

Syntax

UTL_HTTP.CLEAR_COOKIES;

CLOSE_PERSISTENT_CONN Procedure

This procedure closes an HTTP persistent connection maintained by the UTL_HTTP package in the current database session.

See Also:

HTTP Persistent Connections and HTTP Persistent Connections Subprograms

Syntax

UTL_HTTP.CLOSE_PERSISTENT_CONN (
   conn  IN connection);