简体   繁体   English

如何从 PL/SQL 过程中访问 http URL?

[英]How to hit a http URL from PL/SQL procedure?

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production Oracle Database 12c 企业版 12.1.0.2.0 版 - 64 位生产

I am creating an Oracle job where I need to hit a procedure for every 30 minutes,我正在创建一个 Oracle 作业,我需要每 30 分钟执行一次程序,

Inside the procedure, I want to hit a HTTP URL so behind that a java program will execute.在该过程中,我想点击一个 HTTP URL,以便在 Java 程序之后执行。

Approach :方法 :

declare 
 req   UTL_HTTP.REQ;
BEGIN
 req := UTL_HTTP.BEGIN_REQUEST('http://dev.xxx.com/yyy/zzz/aaa/triggerJob');
 dbms_output.put_line('hitting');
EXCEPTION
 WHEN UTL_HTTP.END_OF_BODY THEN
    dbms_output.put_line('exception');
END;

DBMS OUTPUT is hitting DBMS OUTPUT 命中

-- But it is not hitting actually! ——但实际上并没有击中!

Approach 2方法二

declare 
 req   UTL_HTTP.REQ;
 resp  UTL_HTTP.RESP;
BEGIN
 req := UTL_HTTP.BEGIN_REQUEST('http://dev.xxx.com/yyy/zzz/aaa/triggerJob');
 UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
 resp := UTL_HTTP.GET_RESPONSE(req);
UTL_HTTP.END_RESPONSE(resp);
 dbms_output.put_line('hitting');

EXCEPTION
 WHEN UTL_HTTP.END_OF_BODY THEN
    dbms_output.put_line('exception');
END;

With this, I am getting below errors while executing.有了这个,我在执行时遇到了以下错误。

在此处输入图片说明

Consider adding a get_response to actually perform the request;考虑添加一个get_response来实际执行请求; otherwise its only prepared ;) ;否则它只准备;); another good practice is to set the http headers...另一个好的做法是设置 http 标头...

declare 
 req   UTL_HTTP.REQ;
BEGIN
 req := UTL_HTTP.BEGIN_REQUEST('http://dev.xxx.com/yyy/zzz/aaa/triggerJob');
 UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
 UTL_HTTP.GET_RESPONSE(req);

 dbms_output.put_line('hitting');

EXCEPTION
 WHEN UTL_HTTP.END_OF_BODY THEN
    dbms_output.put_line('exception');
END;

more in Oracle documentation Oracle 文档中的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM