How to give Username and password when calling HTTP page?

13,070

You've got two options (assuming the remote server accepts HTTP basic authentication):

  1. you can prepend the url with username:password@url(e.g.
    p_url:='http://username:[email protected]/';)
  2. or you can use the Authorization header. (e.g.
    utl_http.set_header(req, 'Authorization', 'Basic ' || utl_encode.base64_encode('username:password'));)
Share:
13,070
MKN
Author by

MKN

Updated on June 04, 2022

Comments

  • MKN
    MKN almost 2 years

    I have this code when i run this I get credentials error. How to give credentials .The authentication is set to windows in the https page. Means pop up will appear to get the credentials

    declare
          req    UTL_HTTP.REQ;
          resp   UTL_HTTP.RESP;
          value  varchar2(1024);
          p_url  varchar2(4000);
          OPT    varchar2(1000);
        BEGIN
          dbms_output.put_line('');
          p_url:='http://www.xyz.com/';
    
          dbms_output.put_line(p_url);
          req := UTL_HTTP.begin_REQUEST(p_url);
          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;
    
        exception
            when utl_http.end_of_body then
               utl_http.end_response(resp);
        END;
    

    When i run this i get

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <title>401 - Unauthorized: Access is denied due to invalid credentials.</title>
    <style type="text/css">