Skip to Main Content
  • Questions
  • Receive http requests with more than 32k

Breadcrumb

May 4th

Question and Answer

Connor McDonald

Thanks for the question, Norman.

Asked: October 19, 2017 - 4:28 pm UTC

Last updated: June 13, 2022 - 8:42 am UTC

Version: 11.2.0.4

Viewed 10K+ times! This question is

You Asked

Hi Tom,

on more question :)
I´m using the utl_http package to exchange xml-data between different oracle databases.
Until now i´ve requested the mod_plsql (until 11g) or the apache (from 12c) on the other database, posted the data with utl_http.write_text and received it with (name_Array in OWA.vc_arr, value_array in OWA.vc_arr).
Meanwhile my amount of data is growing and growing .... up to over 32k.

Now i´ve ask myself if i could chunk it.

For sure i can set the header "Transfer-Encoding" to chunk the sending side...
utl_http.set_header (l_http_request, 'Transfer-Encoding', 'chunked');
... but how do i get more than 32k on the receiving side?
Maybe you could give me an example.

Thanks for your help :)

and Connor said...

You can read it in chunks, eg

set serverout on
declare
  l_url      varchar2(100) := '[your url]';
  l_req      utl_http.req;
  l_resp     utl_http.resp;
  l_content  clob;
  l_buffer   varchar2(32767);
begin
  dbms_lob.createtemporary(l_content, false);

  l_req  := utl_http.begin_request(l_url);
  l_resp := utl_http.get_response(l_req);

  begin
    loop
      utl_http.read_text(l_resp, l_buffer, 32000);
      dbms_lob.writeappend (l_content, length(l_buffer), l_buffer);
    end loop;
  exception
    when utl_http.end_of_body then
      utl_http.end_response(l_resp);
  end;

  dbms_output.put_line('Size='||length(l_content));

  dbms_lob.freetemporary(l_content);
end;
/




Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Very Useful

Shripad, January 22, 2020 - 9:41 am UTC

This was very useful. We can get the response in chunks.
Could not find this in any documentation.

This saved my life :)

Gnanam, February 18, 2021 - 1:36 pm UTC

its very helpful
Chris Saxon
February 18, 2021 - 6:03 pm UTC

Great to hear :)

Similar approach with JSON response but have number in middle of response

Neel Shah, June 10, 2022 - 8:34 pm UTC

Hello , I am using similar approach to the response greater than 32K below is the snippet of my code
I am not able to parse the chunked response , I see in json response number added in the middle of response .
Please Suggest.
IF (resp_6.STATUS_CODE = UTL_HTTP.HTTP_OK) THEN

DBMS_OUTPUT.PUT_LINE('Response Headers:-');

DBMS_LOB.CREATETEMPORARY(buffer_6, FALSE);

BEGIN
LOOP
UTL_HTTP.READ_TEXT(resp_6, resp_content_6, 32000);
IF (resp_count_header_6 = 0) THEN
-- DBMS_OUTPUT.PUT_LINE(SUBSTR(resp_content_6, 1, (INSTR(resp_content_6,'{')-2)));
resp_content_6 := SUBSTR(resp_content_6, (INSTR(resp_content_6,'{')-1));
resp_count_header_6 := resp_count_header_6 + 1;
END IF;
DBMS_LOB.WRITEAPPEND(buffer_6, LENGTH(resp_content_6), resp_content_6);
-- DBMS_OUTPUT.PUT_LINE(resp_content_6);
-- UTL_HTTP.READ_LINE(resp_6, buffer_6);
-- DBMS_OUTPUT.PUT_LINE(buffer_6);
END LOOP;
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.CLOSE_PERSISTENT_CONNS;
UTL_HTTP.END_RESPONSE(resp_6);
WHEN UTL_HTTP.TOO_MANY_REQUESTS THEN
UTL_HTTP.CLOSE_PERSISTENT_CONNS;
UTL_HTTP.END_RESPONSE(resp_6);
END;
apex_json.parse(buffer_6);
Connor McDonald
June 13, 2022 - 8:42 am UTC

Not sure why you need the hunting for brackets etc, because we are just combining into a lob. New lines etc are not needed

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library