【问题标题】:How to pass post request parameters in Oracle PL/SQL如何在 Oracle PL/SQL 中传递 post 请求参数
【发布时间】:2020-09-19 00:58:27
【问题描述】:

我有一个如下所示的 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;
/

请有人帮我解决这个问题吗?提前致谢!

【问题讨论】:

    标签: oracle plsql oracle18c


    【解决方案1】:

    在您构建请求的第一条语句中,您声明了 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;
    /
    

    【讨论】:

    • 感谢 EJ,但我在哪里或如何设置 --data 中的参数?
    • 刚刚更新了一个例子。您需要使用 UTL_HTTP.WRITE_TEXT 来填充请求的正文。
    猜你喜欢
    • 1970-01-01
    • 2020-10-23
    • 2016-11-05
    • 2013-08-09
    • 1970-01-01
    • 2016-01-25
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多