oracle 调用HTTP页面时如何提供用户名和密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16008796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:34:32  来源:igfitidea点击:

How to give Username and password when calling HTTP page?

oraclemodel-view-controllerauthenticationplsqloracle11g

提问by MKN

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

当我运行此代码时,我有此代码出现凭据错误。如何提供凭据。https 页面中的身份验证设置为 windows。意味着弹出窗口将出现以获取凭据

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">

回答by defectus

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

您有两个选择(假设远程服务器接受 HTTP 基本身份验证):

  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'));)
  1. 你可以在 URL 前面加上 username:password@url(eg
    p_url:='http://username:[email protected]/';)
  2. 或者您可以使用 Authorization 标头。(例如
    utl_http.set_header(req, 'Authorization', 'Basic ' || utl_encode.base64_encode('username:password'));