首页 > 解决方案 > 如何从 SQL 触发 REST API

问题描述

我想从 SQL 中触发 REST API(POST CALL)。我创建了以下程序来做同样的事情。但面临有关 utl_http 包因访问控制列表 (ACL) 拒绝而被拒绝的问题

i have followed the steps mentioned in this article -

http://dbtricks.com/?p=159 

but still getting the below error - 

EXEC schedule_email
Error report -
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "P_STGATGCOMM.SCHEDULE_EMAIL", line 9
ORA-06512: at line 1
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.

below is my procedure

create or replace
procedure schedule_email AS PRAGMA AUTONOMOUS_TRANSACTION;
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://localhost:8080/api/scheduleEmail';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) := '{"email":"sanjeev.rai@yopmail.com", "subject":"This isa subject", "body":"This isa body", "dateTime":"2019-09-03T15:20:00","timeZone":"Asia/Kolkata"}';
begin
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
-- utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'application/json');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req);
 -- process the response from the HTTP call
begin
    loop
utl_http.read_line(res, buffer);
    dbms_output.put_line(buffer);
    end loop;
    utl_http.end_response(res);
  exception
    when utl_http.end_of_body
    then
      utl_http.end_response(res);
  end;
end schedule_email;

标签: sqlrestspring-bootsql-server-2008

解决方案


推荐阅读