'How to hit a http URL from PL/SQL procedure?

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

I am creating an Oracle job where I need to hit a procedure for every 30 minutes,

Inside the procedure, I want to hit a HTTP URL so behind that a java program will execute.

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

-- 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.

enter image description here



Solution 1:[1]

Consider adding a get_response to actually perform the request; otherwise its only prepared ;) ; another good practice is to set the http headers...

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J. Chomel