Oracle 使用utl_http 传送大于32kb数据解决方案
UTL_HTTP Post Data larger than 32KB
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.
如果BODY 内容超过32KB header需要增加
utl_http.set_header(utl_req
,'Transfer-Encoding'
,'chunked');
示例
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'
,'application/json;charset=utf-8');
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;
提示需要注意 字符长度超长
-- 刘轶鹤