大数据传输会比较长时间导致超时,可以通过Utl_http.set_transfer_timeout (600);来设置时间,单位是秒
DECLARE
A NUMBER;
BEGIN
Utl_http.set_transfer_timeout (600);
utl_http.get_transfer_timeout (A);
dbms_output.put_line (A);
END;
主要是 utl_http.set_header(v_http_req, ‘Content-Length’, l_length);这个方法
由于每次写入一行有产生换行符,所以写入了多少行就加上行数的2倍
Procedure get_http_resp(p_xml_char In CLOB, p_ws_url In Varchar2) Is
v_http_req utl_http.req;
V_STR VARCHAR2(32767);
V_LOB_SIZE NUMBER; --lob长度--
l_length NUMBER := 0;
l_offect NUMBER := 0; --每次读取的长度
l_start NUMBER := 1; --开始读取的位置
l_position NUMBER := 1; --上一次的位置
Begin
V_LOB_SIZE := DBMS_LOB.GETLENGTH(p_xml_char);
FOR I IN 1 .. g_count LOOP
l_start := l_start + l_offect;
l_offect := DBMS_LOB.instr(p_xml_char, '<item>', 1, i) - l_position;
l_position := DBMS_LOB.instr(p_xml_char, '<item>', 1, i);
V_STR := DBMS_LOB.SUBSTR(p_xml_char, l_offect, l_start);
l_length := l_length + lengthb(V_STR);
end loop;
if g_count > 0 then
V_STR := DBMS_LOB.SUBSTR(p_xml_char,
V_LOB_SIZE - l_position + 2,
l_start + l_offect);
l_length := l_length + lengthb(V_STR)+g_count*2;
end if;
v_http_req := utl_http.begin_request(p_ws_url,
'POST',
utl_http.http_version_1_1);
--设置编码
utl_http.set_header(v_http_req,
'Content-Type',
'text/xml; charset=utf-8');
utl_http.set_body_charset(v_http_req, 'utf-8');
utl_http.set_header(v_http_req, 'Content-Length', l_length);
l_offect := 0; --每次读取的长度
l_start := 1; --开始读取的位置
l_position := 1; --上一次的位置
FOR I IN 1 .. g_count LOOP
l_start := l_start + l_offect;
l_offect := DBMS_LOB.instr(p_xml_char, '<item>', 1, i) - l_position;
l_position := DBMS_LOB.instr(p_xml_char, '<item>', 1, i);
V_STR := DBMS_LOB.SUBSTR(p_xml_char, l_offect, l_start);
utl_http.write_line(v_http_req, v_str);
end loop;
if g_count > 0 then
V_STR := DBMS_LOB.SUBSTR(p_xml_char,
V_LOB_SIZE - l_position + 2,
l_start + l_offect);
utl_http.write_line(v_http_req, v_str);
log(V_STR);
end if;
gv_http_resp := utl_http.get_response(v_http_req);
log(gv_http_resp.status_code);
log(gv_http_resp.reason_phrase);
If gv_http_resp.reason_phrase <> 'OK' Then
utl_http.end_response(gv_http_resp);
End If;
Exception
When utl_http.end_of_body Then
utl_http.end_response(gv_http_resp);
When Others Then
log(Sqlcode || '_' || Sqlerrm);
End get_http_resp;