This discussion is archived
3 Replies Latest reply: Feb 8, 2012 6:58 AM by cjmurray RSS

utl_http : bugs in authentication example

trent Expert
Currently Being Moderated
Source: http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/u_http.htm#ARPLS070

The below example that is on that documentation page references some elements that no longer exist:

- UTL_HTTP.HTTP_RESPONSE_ERROR_CHECK(FALSE);

This has become: utl_http.get_response_error_check;

It also is expecting an OUT parameter

- UTL_HTTP.GET_HEADER(resp, i, name, value);
DBMS_OUTPUT.PUT_LINE(name || ': ' || value);

References 'name' and 'value' that are not declared anywhere
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;