Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get Gzip Encoded response from API

Josep CamposJan 15 2024

I'm calling to an API from a Procedure.

This API is sending the response with GZIP compression:

l_http_request := utl_http.begin_request('http://api.test.com/v1/testService?date=2024-01-03', 'GET', 'HTTP/1.1');

utl_http.set_header(l_http_request, 'Accept-Encoding', 'gzip,deflate');
utl_http.set_header(l_http_request, 'Connection', 'Keep-Alive');

l_http_response := utl_http.get_response(l_http_request);

If I get the response with “read_text”

utl_http.read_text(l_http_response, l_response_text);

I get an unreadable response:

‹]Gr®ç~Š‚Æ&÷˞ …….

If I use “utl_compress.lz_uncompress” to uncompress the response:

-- Copy the response into the BLOB.
begin
loop
utl_http.read_raw(l_http_response, l_raw, 32766);
dbms_lob.writeappend (l_blob, utl_raw.length(l_raw), l_raw);
end loop;
exception
when utl_http.end_of_body then
utl_http.end_response(l_http_response);
end;

l_blob := utl_compress.lz_uncompress(l_blob);

If I print this blob, I only get numbers:

dbms_output.put_line( utl_raw.cast_to_raw(dbms_lob.substr(l_blob,200,1)) );

-→ 37423041323032303232363436313734363132323341323035423 ….

Is utl_compress the best way to do this?

Regards,

Josep

This post has been answered by Anton Scheffer-Oracle on Jan 15 2024
Jump to Answer
Comments
Post Details
Added on Jan 15 2024
4 comments
937 views