declare
req utl_http.req;
resp utl_http.resp;
url varchar2(4000) :=
'http://10.xx.xx.xx:8085/WebService.asmx'
;
soap_env varchar2(4000);
buffer varchar2(32767);
utf8_data clob;
raw_data raw(32767);
raw_buffer raw(32767);
line varchar2(32767);
idx
integer
:= 1;
begin
soap_env :=
'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">'
||
'<soap:Header/>'
||
'<soap:Body>'
||
' <tem:testProcedure>'
||
' <tem:sInput>'
||
' testConnect + 中文test'
||
'</tem:sInput>'
||
' </tem:testProcedure>'
||
'</soap:Body>'
||
'</soap:Envelope>'
;
req := utl_http.begin_request(url,
'POST'
,
'HTTP/1.1'
);
utl_http.set_header(req,
'Content-Type'
,
'application/soap+xml; charset=utf-8'
);
utl_http.set_header(req,
'Content-Length'
, length(soap_env));
utl_http.write_text(req, soap_env);
resp := utl_http.get_response(req);
dbms_lob.createtemporary(utf8_data,
true
);
loop
begin
utl_http.read_raw(resp, raw_buffer, 32767);
dbms_lob.writeappend(utf8_data,
utl_raw.length(raw_buffer),
utl_raw.cast_to_varchar2(raw_buffer));
exception
when
utl_http.end_of_body
then
exit;
when
others
then
dbms_output.put_line(
'在读取响应时发生错误: '
|| sqlerrm);
exit;
end
;
end
loop;
utl_http.end_response(resp);
idx := 1;
while idx <= dbms_lob.getlength(utf8_data) loop
line := dbms_lob.substr(utf8_data, 255, idx);
dbms_output.put_line(line);
idx := idx + 255;
end
loop;
dbms_lob.freetemporary(utf8_data);
exception
when
utl_http.end_of_body
then
utl_http.end_response(resp);
when
others
then
dbms_output.put_line(
'在调用Web服务时发生错误: '
|| sqlerrm);
if dbms_lob.istemporary(utf8_data) = 1
then
传参的中文会乱码,但是方法内部的中文不会乱码
dbms_lob.freetemporary(utf8_data);
end
if;
end
;
/