How to store the response body for non-200 responses in Oracle UTL_HTTP?

I find that if I call UTL_HTTP.GET_RESPONSE

and get an error response (in this case 500) when I call UTL_HTTP.READ_TEXT

it fails with ORA-29261: bad argument

. How can I see the response body when an error occurs?

+3


source to share


2 answers


The solution turned out to be to call

UTL_HTTP.set_response_error_check(false);

      



before executing the request.

+2


source


What I've done in the past is to read the headers and then do a read_line to get the individual lines of the response:



v_resp := utl_http.get_response (v_req);

v_status := v_resp.status_code;

FOR i IN 1..UTL_HTTP.GET_HEADER_COUNT(v_resp) LOOP
  utl_http.get_header(v_resp, i, v_name, v_value);
  dbms_output.put_line(v_name || ': ' || v_value);
END LOOP;

BEGIN
  utl_http.read_line(v_resp, v_value, TRUE);
  v_response := v_value;
  dbms_output.put_line(v_value);
EXCEPTION
  WHEN OTHERS THEN
    NULL;  -- handle exception here
END;

      

+2


source







All Articles