0

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.

Greg Reynolds
  • 9,736
  • 13
  • 49
  • 60
  • What solution are you looking for? If you don't get a 200 response then you should ignore the body, but if the transfer was interrupted (say) then it's not unreasonable that some of the content would be available - but not all of it, presumably. Why are you reading it at all? – Alex Poole Feb 24 '23 at 17:30
  • The API I am calling puts the error information in the body and returns a 422 code. Whether it should be doing that or not is out of my control. – Greg Reynolds Feb 27 '23 at 09:13
  • OK, so do you just need to [manually uncomress](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/UTL_COMPRESS.html#GUID-871A2DE4-7C69-431D-920C-FD3450DDB685) the value you get back? – Alex Poole Feb 27 '23 at 09:26
  • It looks like I shall have to do that if there is no setting on UTL_HTTP to do it for me. – Greg Reynolds Feb 27 '23 at 11:44

0 Answers0