--http post
FUNCTION FN_HTTP_POST(v_url VARCHAR2,
v_body VARCHAR2,
v_body_type VARCHAR2) RETURN VARCHAR2 AS
BEGIN
DECLARE
req UTL_HTTP.REQ;
resp UTL_HTTP.RESP;
v_line VARCHAR2(4000);
v_text VARCHAR2(4000);
v_content_length number;
BEGIN
v_text := '';
v_content_length := lengthb(v_body);
if (v_content_length is null) then
v_content_length := 0;
end if;
BEGIN
req := UTL_HTTP.BEGIN_REQUEST(url => v_url, method => 'POST');
UTL_HTTP.SET_BODY_CHARSET('UTF-8');
UTL_HTTP.SET_HEADER(req, 'Content-Type', v_body_type);
utl_http.set_header(req, 'Content-Length', v_content_length);
utl_http.write_text(req, v_body);
resp := UTL_HTTP.GET_RESPONSE(req);
LOOP
UTL_HTTP.READ_LINE(resp, v_line, TRUE);
v_text := v_text || v_line;
END LOOP;
UTL_HTTP.END_RESPONSE(resp);
UTL_HTTP.END_REQUEST(req);
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE(resp);
WHEN OTHERS THEN
UTL_HTTP.END_RESPONSE(resp);
UTL_HTTP.END_REQUEST(req);
END;
return v_text;
END;
END;
oracle通过UTL_HTTP包实现http请求
最新推荐文章于 2023-12-04 08:00:00 发布