如何在 Oracle PL/SQL 中传递 post 请求参数

How to pass post request parameters in Oracle PL/SQL

我有如下所示的 cURL 命令:

curl --insecure -X POST https://www.example.com -H 'accept-encoding: gzip,deflate' -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded' --data "request_type=secure&scope=global&user_id=temp&password=temppass"

我不确定,我需要如何从 PL/SQL 过程中调用此 POST 请求。

尤其是我不知道如何传递--data参数。

DECLARE
    http_request    UTL_HTTP.req;
    http_response   UTL_HTTP.resp;
    return_text VARCHAR2(2000);
BEGIN
    http_request := UTL_HTTP.begin_request('https://www.example.com/path/sub_path');

    UTL_HTTP.set_header(http_request, 'accept-encoding', 'gzip,deflate');
    UTL_HTTP.set_header(http_request, 'cache-control', 'no-cache');
    UTL_HTTP.set_header(http_request, 'content-type', 'application/x-www-form-urlencoded');

    UTL_HTTP.set_authentication(http_request, 'temp', 'temppass');

    http_response := UTL_HTTP.get_response(http_request);

    UTL_HTTP.read_text(http_response, return_text);
    dbms_output.put_line (return_text);
END;
/

谁能帮我解决这个问题?提前致谢!

在构建请求的第一条语句中,声明了 HTTP 方法。

http_request := UTL_HTTP.begin_request('https://www.example.com/path/sub_path','POST');

可以找到有关如何发送带有正文的请求的示例 here

您的代码示例:

DECLARE
    http_request    UTL_HTTP.req;
    http_response   UTL_HTTP.resp;
    return_text     VARCHAR2 (2000);
BEGIN
    http_request := UTL_HTTP.begin_request ('https://www.example.com/path/sub_path', 'POST');

    UTL_HTTP.set_header (http_request, 'accept-encoding', 'gzip,deflate');
    UTL_HTTP.set_header (http_request, 'cache-control', 'no-cache');
    UTL_HTTP.set_header (http_request, 'content-type', 'application/x-www-form-urlencoded');

    UTL_HTTP.set_authentication (http_request, 'temp', 'temppass');

    UTL_HTTP.write_text (http_request,
                         'request_type=secure&scope=global&user_id=temp&password=temppass');

    http_response := UTL_HTTP.get_response (http_request);

    UTL_HTTP.read_text (http_response, return_text);
    DBMS_OUTPUT.put_line (return_text);
END;
/