How To Post Data larger than 32KB To a Url Using UTL_HTTP?
Question: How To Post Data larger than 32KB To a Url Using UTL_HTTP?
Is there a way to post Data larger than 32KB using utl_http.write_text?
Answer: Yes, You can post Data larger than 32KB to a Web Service (URL) using UTL_HTTP.
You would have to set header parameter “Transfer-Encoding” as a “chunked”
and then send your data in chunks.
============================
Here is the sample script
============================
CREATE OR REPLACE FUNCTION xx_utl_http(p_url varchar2,
p_request_body clob
)
RETURN VARCHAR2 AS
utl_req UTL_HTTP.req;
utl_resp UTL_HTTP.resp;
req_length binary_integer;
response_body CLOB;
resp_length binary_integer;
buffer varchar2 (2000);
amount pls_integer := 2000;
offset pls_integer := 1;
BEGIN
utl_req := UTL_HTTP.begin_request (p_url, ‘POST’, ‘HTTP/1.1’);
UTL_HTTP.set_header (utl_req, ‘Content-Type’, ‘text/xml’);
req_length := DBMS_LOB.getlength (p_request_body);
— If Message data under 32kb limit
if req_length<=32767
then
UTL_HTTP.set_header (utl_req, ‘Content-Length’, req_length);
UTL_HTTP.write_text (utl_req, p_request_body);
— If Message data more than 32kb
elsif req_length>32767
then
UTL_HTTP.set_header (utl_req, ‘Transfer-Encoding’, ‘chunked’);
WHILE (offset < req_length)
LOOP
DBMS_LOB.read (p_request_body,
amount,
offset,
buffer);
UTL_HTTP.write_text (utl_req, buffer);
offset := offset + amount;
END LOOP;
end if;
utl_resp := UTL_HTTP.get_response (utl_req);
UTL_HTTP.read_text (utl_resp, response_body, 32767);
UTL_HTTP.end_response (utl_resp);
RETURN response_body;
END;
==========
Keywords
==========
UTL_HTTP, Oracle Web Service, 32kb, XML POST larger than 32kb, clob POST larger than 32kb
Truly difficult to get skillful persons on this subject topic, you seem like you understand what you are dealing with! With thanks
Incredible posting, I seriously enjoy updates by you.