I have a very strange problem with UTL_HTTP. I'm calling an API that can return a gzip encoded response. This is handled correctly when the service returns a 200 status code. However, when I try using get_text or get_raw on the response when the status is not 200, I get the raw gzip data. I've verified this by using rawtohex to examine the response and it has the initial hex value of 1F8B i.e. the magic number for a gzip file.
declare
l_raw raw(32767);
BEGIN
LOOP
UTL_HTTP.read_raw (l_UtlResp, l_raw, 32767);
dbms_output.put_line (rawtohex(l_raw));
END LOOP;
UTL_HTTP.end_response (l_UtlResp);
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
null;
WHEN UTL_HTTP.transfer_timeout THEN
WHEN OTHERS THEN
RAISE;
END;
Outputs a string like
1F8B08000000000000006D504D4BC43010F...
I've exhausted my Google search skill trying to find a solution for this.