REM REM utlhttp.sql REM REM Copyright (c) 1996, 2008, Oracle. All rights reserved. REM REM NAME REM utlhttp.sql - HTTP requests from stored programs REM REM DESCRIPTION REM Package contains functions and procedures to make HTTP requests from REM stored programs. REM REM NOTES REM None REM REM MODIFIED (MM/DD/YY) REM rpang 02/01/08 - Misc Amazon S3 enhancements REM rpang 09/27/06 - Added network_access_denied exception REM rpang 05/04/06 - Made invoker rights routine REM sursrini 07/23/03 - 2467239: Support Expect 100 Continue REM sylin 12/06/02 - 2351330: Add NCAHR support REM sursrini 10/23/02 - 2528866: Added support for authentication in URL REM rpang 07/23/01 - 1840818: explain unsupported character set cond'n REM rpang 06/06/01 - 1777438: noted new exceptions from begin_request REM gviswana 05/25/01 - CREATE OR REPLACE SYNONYM REM rpang 04/02/01 - Updated example REM rpang 02/20/01 - Added set_transfer_timeout for request REM rpang 02/16/01 - Added partial_multibyte_char exception REM rpang 02/12/01 - Moved get_response to response API category REM rpang 02/12/01 - Set default value for set_cookie_support to TRUE REM rpang 01/16/01 - Changed resolution of timeout to seconds REM rpang 01/08/01 - Modified persistent connection descriptor REM rpang 12/06/00 - Added set_cookie_support for request REM rpang 11/27/00 - Modified session-default API REM rpang 10/20/00 - Added SSL information to connecton record REM rpang 10/05/00 - Noted that method field is also updated on redir REM rpang 09/01/00 - Added function get_body_charset REM rpang 08/17/00 - Fixed comments REM rpang 07/26/00 - Added configuration API REM rpang 07/21/00 - Added charset API REM rpang 05/23/00 - Added new API REM jmuller 10/07/99 - Fix bug 708690: TAB -> blank REM rpang 09/03/99 - Should set wallet before making request REM rpang 08/04/99 - Extended API to support HTTPS REM jmuller 05/28/99 - Fix bug 708690: TAB -> blank REM rdecker 08/20/98 - add proxy param to request calls REM jmuller 08/21/98 - Fix bug 500845: add documentation on proxies REM gclossma 04/25/97 - raw => number for ptr_t REM gclossma 01/30/97 - fix documentation REM gclossma 01/28/97 - add fetch_more_data REM gclossma 12/11/96 - add grant to public REM gclossma 12/10/96 - for 7.3.3 REM gclossma 08/28/96 - utl_SQurL => utl_http REM gclossma 08/19/96 - SQurL http callouts REM gclossma 08/19/96 - Created CREATE OR REPLACE PACKAGE utl_http AUTHID CURRENT_USER IS /****************************************************************** The UTL_HTTP package makes Hypertext Transfer Protocol (HTTP) callouts from SQL and PL/SQL. It can be used to access data on the Internet over the HTTP protocol. The package contains a set of API that enables users to write PL/SQL programs that communicate with Web (HTTP) servers. It also contains a function that can be used in SQL queries. Besides the HTTP protocol, it also supports the HTTP protocol over the Secured Socket Layer protocol (SSL), also known as HTTPS, directly or via a HTTP proxy. Other Internet-related data-access protocols (such as the File Transfer Protocol (FTP) or the Gopher protocol) are also supported via a HTTP proxy server that supports those protocols. When the package fetches data from a Web site using the HTTPS protocol, it requires an Oracle wallet to be set up properly by Oracle Wallet Manager. Non-HTTPS fetches do not require an Oracle wallet. The API is divided into a number of categories. The session API manipulates configurations pertaining to the package within a database user session. The request API begins a new HTTP request, manipulates its attributes, and sends information to the Web server. The response API returns the attributes of the response and receives information the response data from the Web server. The cookies API manipulates the HTTP cookies maintained by the package within the database user session. The persistent connection API manipulates the persistent connections maintained by the package. There are also two simple functions that allow users to fetch a Web page by a single function call. The following is an example that illustrate the use of the session, request, and response API to pretend to be the Netscape brower to fetch a Web page. SET serveroutput ON SIZE 40000 DECLARE req utl_http.req; resp utl_http.resp; value VARCHAR2(1024); BEGIN utl_http.set_proxy('proxy.it.my-company.com', '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; The following is another example that illustrates how to use the simple API to fetch a Web page in SQL (only the first 2000 bytes will be returned). SVRMGR> select utl_http.request('http://www.oracle.com/') 2 from dual; UTL_HTTP.REQUEST('HTTP://WWW.ORACLE.COM/') ----------------------------------------------------------