我正在使用一个临时Oracle云帐户。我认为相同的功能可以在Apex Web服务上使用,但不能在UTL_HTTP上使用。因此,这个片段有效,并返回我们正在查找的问题。
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 web服务,我们需要使用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;
但回报:
ORA-29273:HTTP请求失败
ORA-29024:证书验证失败
ORA-06512:在"SYS.UTL_HTTP";,第639行
ORA-06512:在";"SYS.UTL_HTTP";,线路1415 ORA-06512…
关键是UTL_HTTP.SET_WALLET('');
。您需要在初始http请求之前设置钱包(带有空字符串参数(。以下代码片段在Oracle Cloud ATP(自主转换处理(数据库中进行了测试:
- 设置网络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;
- 测试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;
参见官方文件和示例(在页面底部(:
在某种程度上,@OldProgrammer从29-12-2020米回答了这个问题,但我不知道如何给出答案。
我需要将UTL_HTTP代码耦合到默认钱包,或者创建一个新钱包。APEX_WEB_SERVICE可能会隐式地执行此操作,而UTL_HTTP必须将其拼写出来。
我的问题是针对Oracle Cloud的,我无法使OldProgrammers链接中的工具链在Oracle Cloud中工作。推出了一个虚拟机,它就工作了。