How to keep response body on non-200 responses in

2019-07-06 16:46发布

I find that if I call UTL_HTTP.GET_RESPONSE and get an error response (500 in this case), when I call UTL_HTTP.READ_TEXT it fails with ORA-29261: bad argument. How can I see the response body when there is an error?

标签: oracle http
2条回答
手持菜刀,她持情操
2楼-- · 2019-07-06 17:24

The solution ended up being to call

UTL_HTTP.set_response_error_check(false);

before making the request.

查看更多
霸刀☆藐视天下
3楼-- · 2019-07-06 17:25

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

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;
查看更多
登录 后发表回答