数据库http请求发送clob

Click to add to Favorites How to POST and RECEIVE a response as a CLOB using UTL_HTTP? (Doc ID 1375312.1) To BottomTo Bottom

In this Document
Goal
Solution
APPLIES TO:
PL/SQL - Version 11.2.0.3 and later
Information in this document applies to any platform.
GOAL
How to POST and RECEIVE a response as a CLOB using UTL_HTTP?

SOLUTION

create or replace function PostRecClob(url varchar2, request clob) return clob as
  req utl_http.req;
  resp utl_http.resp;
  length binary_integer;
  response clob;
  buffer varchar2(32767);
  amount pls_integer := 32767;
  offset pls_integer := 1;
begin
  req := utl_http.begin_request(url, 'POST', 'HTTP/1.1');
  utl_http.set_header(req, 'Content-Type', 'text/xml');
  utl_http.set_header(req, 'Transfer-Encoding', 'chunked');
  length := dbms_lob.getlength(request);

  while(offset < length) loop
    dbms_lob.read(request, amount, offset, buffer);
    utl_http.write_text(req, buffer);
    offset := offset + amount;
  end loop;
  resp := utl_http.get_response(req);

-- Code to read the response in 32k chunks
  dbms_lob.createtemporary(response, false);
  begin
   loop
    utl_http.read_text(resp, buffer);
    dbms_lob.writeappend(response, dbms_lob.getlength(buffer), buffer);
   end loop;
  utl_http.end_response(resp);
  exception
   when utl_http.end_of_body then
   utl_http.end_response(resp);
  end;
return response;
end;
/

Sample Code to call or execute the function PostRecClob:

set serverout on
declare
  request clob;
  xmlrequest xmltype;
  response clob;
  xmlresponse xmltype;
  data clob;
begin
  for i in 1..1000 loop
    request := request||'ABCDEFGH';
  end loop;
  response := PostRecClob('http://Your_URL/YourServlet', request);
  dbms_output.put_line(response);
end;
/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值