欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Oracle 通过UTL_HTTP发送http请求

程序员文章站 2022-03-28 13:50:10
...

HTTP_GET:

CREATE OR REPLACE FUNCTION FN_HTTP_GET (v_url  VARCHAR2)
RETURN VARCHAR2
AS
BEGIN
  DECLARE
  req UTL_HTTP.REQ;
  resp UTL_HTTP.RESP;
  v_line VARCHAR2 ( 4000 );
  v_text VARCHAR2 ( 4000 );
  BEGIN
    v_text := '';
    BEGIN
      req := UTL_HTTP.BEGIN_REQUEST ( url => v_url, method => 'GET' );
      UTL_HTTP.SET_BODY_CHARSET('UTF-8');
      UTL_HTTP.SET_HEADER(req, 'Content-Type', 'application/x-www-form-urlencoded');
      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请求

相关标签: oracle