数据库存储过程代码
CREATE OR REPLACE PROCEDURE FSMT.P_GET_HTTP_RES /* 描述:存儲過程掉用HTTP接口 作者:Janus 日期:2023-11-23 */ ( M_DOC_NO IN VARCHAR2, --?? M_DOC_TYPE IN VARCHAR2,--?据?型 M_STANDBY IN VARCHAR2, --?用字段 M_EMP IN VARCHAR2, --?工? RES OUT VARCHAR2 --返回值 ) AS REQ utl_http.req; RESP utl_http.resp; V_LINE varchar2(4000); V_TEXT varchar2(4000); L_BODY varchar2(4000); L_RES varchar2(200); L_MSG varchar2(4000); RESVALUE varchar2(200); L_ADD varchar2(400); BEGIN L_BODY := ' {"msgid":"12313","usercode":"F2903004","show_notification_flag":1,"play_title_voice_flag":"1","Title":"123131","content":"1231231","query_url":"http://10.74.14.38/assets/ad8bebfbfe627.jpg"}'; L_ADD:='http://172.16.3.82:18848/sys-message/send_alarm_ulist'; REQ := utl_http.begin_request(url =>L_ADD, method =>'POST'); utl_http.set_body_charset('UTF-8'); utl_http.set_header(REQ, 'Content-Type', 'application/json'); utl_http.set_header(REQ, 'Authorization', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJGMjkwMzAwNCIsImlhdCI6MTcwMDQ3MTY0NCwiZXhwIjo3NzQ4NDcxNjQ0fQ.arfdRpFzQFfDC681dU4zWqjEe3CCCS1LGWEVuDi9_WS_r1aks2CG8ooNj-jyaCUWyvv_h9cHPohrblJjMuNc3A'); utl_http.set_header(REQ, 'Content-Length', lengthb(L_BODY)); utl_http.write_text(REQ, L_BODY); RESP := utl_http.get_response(REQ); utl_http.end_response(resp); utl_http.end_request(req); exception when utl_http.end_of_body then utl_http.end_response(RESP); RETURN; when others then dbms_output.put_line(sqlerrm); utl_http.end_response(resp); utl_http.end_request(req); RES := 'NG:' ||sqlerrm ; RETURN; end;
要想Oracle 访问网络接口,还需要赋予必要权限
begin dbms_network_acl_admin.create_acl ( acl => 'utlhttpfsmt.xml', -- 文件名称 description => 'HTTP Access', -- 描述 principal => 'FSMT', -- 授权或者取消授权账号,大小写敏感 is_grant => TRUE, -- 授权还是取消授权 privilege => 'connect', -- 授权或者取消授权的权限列表 start_date => NULL, -- 起始日期 end_date => NULL -- 结束日期 ); commit; end; ------------------------------------------------------------------------------------------ begin dbms_network_acl_admin.add_privilege ( -- 添加访问权限列表项 acl => 'utlhttpfsmt.xml', -- 刚才创建的acl名称 principal => 'FSMT', -- 授权或取消授权用户 is_grant => TRUE, -- 与上同 privilege => 'connect', -- 权限列表 connect即可 start_date => NULL, end_date => NULL ); commit; end; --------------------------------------------------------------------------------------------- begin dbms_network_acl_admin.assign_acl ( -- 该段命令意思是允许访问acl名为utl_http.xml下授权的用户,使用oracle网络访问包,所允许访问的目的主机,及其端口范围。 acl => 'utlhttpfsmt.xml', host => '172.16.3.82', -- ip地址或者域名,填写 -- 且建议使用ip地址或者使用域名,若用localhost,当oracle不是安装在本机上的情况下,会出现问题 lower_port => 10000, -- 允许访问的起始端口号 upper_port => 30000 -- 允许访问的截止端口号 ); commit; end;
查看权限是否已经存在
SELECT* FROM dba_network_acl_privileges; SELECT * FROM dba_network_acls
找一个已经写好的测试接口如图
完结!
标签:http,SpringBoot,--,REQ,utl,acl,API,Oracle,end From: https://www.cnblogs.com/janus2003/p/17858414.html