我已经使用DBMS_NETWORK_ACL_ADMIN软件包设置了ACL。在这里
但是当我尝试使用GET连接到上述Web服务时,出现错误
ORA-29273: HTTP request failed
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_HTTP", line 368
ORA-06512: at "SYS.UTL_HTTP", line 1118
ORA-06512: at "APEX_040200.WWV_FLOW_WEB_SERVICES", line 550
ORA-06512: at "APEX_040200.WWV_FLOW_WEBSERVICES_API", line 197
ORA-06512: at line 7
29273. 00000 - "HTTP request failed"
*Cause: The UTL_HTTP package failed to execute the HTTP request.
*Action: Use get_detailed_sqlerrm to check the detailed error message.
Fix the error and retry the HTTP request.
我也要提到主机oracle-base.com运行良好。下面的代码工作正常。
declare
l_response CLOB;
l_url varchar2(4000) := 'http://oracle-base.com/webservices/add-numbers.php'; --web service URL
l_result NUMBER;
begin
---get XML from
l_response := apex_web_service.make_rest_request(p_url => l_url,
p_http_method => 'GET',
p_parm_name => apex_util.string_to_table('p_int_1:p_int_2'),
p_parm_value => apex_util.string_to_table('12:12')
);
dbms_output.put_line(l_response);
--parse the response
l_result :=apex_web_service.parse_xml(p_xml => XMLTYPE(l_response), --convert CLOB to XML
p_xpath => '//number/text()'
);
dbms_output.put_line(l_result);
end;
但是当我尝试对reqres.re进行相同操作时,它会失败。我如何添加reqres.in
DECLARE
l_principal VARCHAR2(20) := 'APEX_040200';
--l_principal VARCHAR2(20) := 'APEX_050000';
--l_principal VARCHAR2(20) := 'APEX_050100';
--l_principal VARCHAR2(20) := 'APEX_180200';
BEGIN
DBMS_NETWORK_ACL_ADMIN.append_host_ace (
host => 'reqres.in',
lower_port => 80,
upper_port => 80,
ace => xs$ace_type(privilege_list => xs$name_list('http'),
principal_name => l_principal,
principal_type => xs_acl.ptype_db));
END;
/
我正在尝试执行的命令:
declare
l_response CLOB;
l_url varchar2(4000) := 'https://reqres.in/api/users?page=2'; --web service URL
l_result NUMBER;
begin
---get XML from
l_response := apex_web_service.make_rest_request(p_url => l_url,
p_http_method => 'GET'
-- p_parm_name => apex_util.string_to_table('p_int_1:p_int_2'),
-- p_parm_value => apex_util.string_to_table('12:12')
);
dbms_output.put_line(l_response);
----parse the response
--l_result :=apex_web_service.para(p_xml => XMLTYPE(l_response), --convert CLOB to XML
-- p_xpath => '//number/text()'
-- );
dbms_output.put_line(l_result);
--APEX_JSON.parse(l_result); -- APEX_JSON is not available
end;
要发出HTTPS请求,您需要做的第一件事是指定正确的端口。 HTTPS使用443,而HTTP使用80:
DBMS_NETWORK_ACL_ADMIN.append_host_ace (
host => 'reqres.in',
lower_port => 443,
upper_port => 443,
ace => xs$ace_type(....
这应该消除ORA-24247: network access denied by access control list (ACL)
错误。但是,这样做之后,您可能会收到ORA-29024: Certificate validation failure
错误。
如果发生这种情况,您需要创建一个Oracle电子钱包来存储https://reqres.in/使用的根证书(即Sectigo证书),确保数据库有权读取该钱包,并将钱包详细信息添加到呼叫apex_web_service.make_web_request
:
apex_web_service.make_web_request