Set up Oracle 12c R1 to connect to web service

风流意气都作罢 提交于 2021-01-29 13:09:29

问题


I have set up ACL using DBMS_NETWORK_ACL_ADMIN package. Here it's

But when I am trying to connect to the above web service using GET, I am getting error

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.

I would also like to mention host oracle-base.com is working perfectly. below code works fine.

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;

but when I am tryig to do the same for reqres.in it's getting failed. How I added 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;
/

The command I am trying to execute :

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;

回答1:


To make an HTTPS request, the first thing you need to do is to specify the correct port. HTTPS uses 443 whereas HTTP uses 80:

     DBMS_NETWORK_ACL_ADMIN.append_host_ace (
       host       => 'reqres.in', 
       lower_port => 443,
       upper_port => 443,
       ace        => xs$ace_type(....

This should get rid of the ORA-24247: network access denied by access control list (ACL) error. However, after doing this, you may get a ORA-29024: Certificate validation failure error instead.

If this happens, you'll need to create an Oracle Wallet to store the root certificate used by https://reqres.in/ (i.e. the Sectigo one), ensure that the database has permission to read this wallet, and add the wallet details to the call to apex_web_service.make_web_request:

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')
  p_wallet_path => 'path/to/your/wallet',
  p_wallet_pwd => 'YourWalletPasswordHere'
);


来源:https://stackoverflow.com/questions/58577403/set-up-oracle-12c-r1-to-connect-to-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!