1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| DECLARE
request UTL_HTTP.REQ;
response UTL_HTTP.RESP;
buff VARCHAR2(4000);
clob_buff CLOB;
url varchar(500):='https://restcountries.eu/rest/v2/all';
BEGIN
UTL_HTTP.SET_RESPONSE_ERROR_CHECK(true);
UTL_HTTP.SET_WALLET('file:C:\oracle\certifs', 'pays12345');
request := UTL_HTTP.begin_request(url => url, METHOD => 'GET', https_host => 'restcountries.eu');
response := UTL_HTTP.GET_RESPONSE(request);
DBMS_OUTPUT.PUT_LINE('HTTP response status code: ' || response.status_code);
IF response.status_code = 200 THEN
BEGIN
clob_buff := EMPTY_CLOB;
LOOP
UTL_HTTP.READ_TEXT(response, buff, LENGTH(buff));
clob_buff := clob_buff || buff;
END LOOP;
UTL_HTTP.END_RESPONSE(response);
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE(response);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
UTL_HTTP.END_RESPONSE(response);
END;
DBMS_OUTPUT.PUT_LINE('RESULT : '||clob_buff);
ELSE
DBMS_OUTPUT.PUT_LINE('ERROR');
UTL_HTTP.END_RESPONSE(response);
END IF;
END;
/ |