Tuesday, September 14, 2021
Read internet pages with utl_http in oracle autonomous database
In oracle autonomous database you have some tricks how to read HTTPS pages from database.
First is that you do not have to create wallet with public keys of pages you will call from database. All mayor trusted issuers have database build in. You use code: utl_http.set_wallet( '' );
If you would like to acces untrusted sites (database do not know issuers) or HTTP sites you have to use one of providers-proxies that converts trafic to trusted HTTP site.
Do not forget to register URLs in ACL
Some samples:
utl_http.set_wallet( '' );
declare
pieces utl_http.html_pieces;
begin
pieces := utl_http.request_pieces('https://sourceforge.net/p/rasd/code-0/feed');
for i in 1 .. pieces.count loop
v_project := v_project || pieces(i);
end loop;
end;
declare
req UTL_HTTP.REQ;
resp UTL_HTTP.RESP;
value VARCHAR2(1024);
begin
req := UTL_HTTP.BEGIN_REQUEST('https://api.github.com/repos/DomenDolar/RASD/commits');
UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
resp := UTL_HTTP.GET_RESPONSE(req);
LOOP
UTL_HTTP.READ_TEXT(resp, value, 1000);
v_gitd := v_gitd || value;
END LOOP;
UTL_HTTP.END_RESPONSE(resp);
exception when UTL_HTTP.end_of_body then
UTL_HTTP.END_RESPONSE(resp);
end;
select URIFACTORY.getUri('https://sourceforge.net/p/rasd/code-0/feed').getClob() ,
URIFACTORY.getUri('https://sourceforge.net/projects/rasd/rss?path=/').getClob() ,
URIFACTORY.getUri('https://sourceforge.net/p/rasd/discussion/hintsandtipsrasd/feed.rss').getClob()
into v_project, v_code , v_forum
from dual;
