Oracle Cloud > utl_http 失败并出现 ORA-29273:HTTP 请求失败 ORA-29024:证书验证失败 ORA-06512

Oracle Cloud > utl_http fails with a ORA-29273: HTTP request failed ORA-29024: Certificate validation failure ORA-06512

我正在使用一个临时的 Oracle Cloud 帐户。我认为相同的功能适用于 Apex Web 服务,但不适用于 UTL_HTTP。所以这段代码有效,returns 我们正在寻找的问题。

DECLARE   
   L_json_response     varchar2(32767);
BEGIN   
   apex_web_service.g_request_headers(1).name := 'Content-Type';   
   apex_web_service.g_request_headers(1).Value := 'application/json';         
   L_json_response := apex_web_service.make_rest_request ( p_url => 
   'https://mycompany.atlassian.net/rest/api/3/issue/BLABLA-23862', p_http_method => 'GET', 
    p_username => 'My.Username@mycompany', p_password => 'osBJWHhPasdffNVOQ5AA11D5'); -- Password is my Jira API Token      
   EXCEPTION WHEN OTHERS THEN raise_application_error(-20001,'An error was encountered - 
  '||SQLCODE||' -ERROR- '||SQLERRM);
END;

我无法在最终产品中使用 Apex 网络服务,我们需要使用 UTL_HTTP。根据我的理解,这个片段应该做同样的事情:

DECLARE
    req utl_http.req;
    res utl_http.resp;
    url varchar2(4000) := 'https://mycompany.atlassian.net/rest/api/3/issue/BLABLA-23862';
    buffer varchar2(4000);
BEGIN
    req := utl_http.begin_request(url, 'GET');
    utl_http.set_header(req, 'Content-Type', 'application/json');
    utl_http.set_header(req, 'Authorization', 'Basic ' || utl_encode.base64_encode('my.msername@mycompany:osBJWHhPasdffNVOQ5AA11D5'));

    res := utl_http.get_response(req);
    utl_http.read_text(res, buffer);
END;

但是returns:

ORA-29273: HTTP request failed
ORA-29024: Certificate validation failure
ORA-06512: at "SYS.UTL_HTTP", line 639
ORA-06512: at "SYS.UTL_HTTP", line 1415 ORA-06512...

@OldProgrammer 在某种程度上回答了 29-12-2020m 的评论,但我不知道如何归因于答案。

我需要将 UTL_HTTP 代码耦合到默认钱包或创建一个新钱包。 APEX_WEB_SERVICE 可能会隐含地执行此操作,而 UTL_HTTP 必须将其拼写出来。

我的问题是针对 Oracle 云的,我无法让来自 OldProgrammers link 的工具链在 Oracle 云中运行。部署了一个 VM,它运行良好。

关键是UTL_HTTP.SET_WALLET('');。您需要在初始 http 请求之前设置钱包(使用空字符串参数)。 以下代码片段在 Oracle 云 ATP(自主转换处理)数据库中进行了测试:

  1. 设置网络ACL
BEGIN
  DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(acl  => 'my_acl.xml',
                                    description => 'ACL for http request.',
                                    principal => 'MY_USER',
                                    is_grant  => true,
                                    privilege => 'connect');
  DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'my_acl.xml',
                                       principal => 'MY_USER',
                                       is_grant  => true,
                                       privilege => 'resolve');
  DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(acl => 'my_acl.xml', host => 'www.oracle.com');
END;
  1. 测试 https 请求
DECLARE
  l_text VARCHAR2(32767);
BEGIN
  UTL_HTTP.SET_WALLET('');
  l_text := UTL_HTTP.REQUEST('https://www.oracle.com/index.html');
  dbms_output.put_line(l_text);
END;

参见 official document and example(在页面底部):