create or replace function Get_Http_Request (
  p_url in varchar2, p_user in varchar2, p_password in varchar2 )

  return varchar2
is
  v_req    Utl_Http.req;
  v_resp   Utl_Http.resp;
  v_name   varchar2(255);

  v_value  varchar2(1023);
  v_buffer varchar2(80);
  v_msg    varchar2(32767);
begin

  Utl_Http.Set_Response_Error_Check ( enable => true );

  Utl_Http.Set_Proxy (
    proxy            => 'www-proxy.us.oracle.com',
    no_proxy_domains => 'us.oracle.com' );

    -- Alternatively use method => 'POST' and Utl_Http.Write_Text to
    -- send an arbitrarily long message


  v_req := Utl_Http.Begin_Request (
    url => p_url,
    method => 'GET' );

  Utl_Http.Set_Authentication (
    r => v_req,
    username  => p_user,
    password  => p_password,

    scheme    => 'Basic',
    for_proxy => false /* this info is for the target web server */ );

  Utl_Http.Set_Header (
    r     => v_req,
    name  => 'User-Agent',
    value => 'Mozilla/4.0' );

  v_resp := Utl_Http.Get_Response ( r => v_req );


  -- You might prefer to test v_resp.status_code explicitly.
  -- The constant Utl.Http.Http_Ok (ie the value 200) is "OK".
  -- Maybe you want to program explicit action for various
  -- other error values of v_resp.status_code.
  --
  -- Since no action is taken here, and ORA-29268 is raised
  -- with a message like "HTTP client error nnn - <some explanation>

  for i in 1..Utl_Http.Get_Header_Count ( r => v_resp )

  loop
    Utl_Http.Get_Header (
      r     => v_resp,
      n     => i,
      name  => v_name,
      value => v_value );
    if lower(v_name) = 'content-type'
    then
      if Instr( Lower(v_value), 'text/xml' ) < 1
        then raise_application_error ( -20997,
          'Get_Http_Request: unexpected Content-Type: ' || v_value ); end if;

    end if;
  end loop;

  -- v_buffer was deliberately declared small to illustrate
  -- the piecewise fetch logic. A real example would use a big buffer
  -- (up to varchar2(32767) and receive arbitrarily long messages.

  begin
    loop
      Utl_Http.Read_Text (
        r     => v_resp,
        data  => v_buffer );

      v_msg := v_msg || v_buffer;
    end loop;
  exception when Utl_Http.End_Of_Body then null;
  end;

  Utl_Http.End_Response ( r => v_resp );
  return v_msg;
end Get_Http_Request;
/