How to sent a POST request as json in plsql

 ̄綄美尐妖づ 提交于 2019-12-03 16:55:31

After a lot of searching, i got the following code from a blog. Works fine for me.

declare
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://192.168.1.194:8080/NotificationApp/sendNotification.rest';
name varchar2(4000);
buffer varchar2(4000); 
content varchar2(4000) := '{"code":100,"id": "APA91bFSmD_gBsUwO_hraRZL20mt8p4ejGn5fC7tlciINT50Ad8oIod2T-64GVk_8rProqXGEpYuDcoQogG0L7a0TuyeeisTcmHiUUONbnZzn4_u0ED7QD_iNeVkh1ZgU8Pa-HRtfgJUgOT-TyvlM9hB4Yn9fvOPud","data": "alert alert"}';

begin

req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0'); 
utl_http.set_header(req, 'content-type', 'application/json'); 
utl_http.set_header(req, 'Content-Length', length(content));

utl_http.write_text(req, content);

res := utl_http.get_response(req);

    begin
    loop
    utl_http.read_line(res, buffer);
    dbms_output.put_line(buffer);

    end loop;
    utl_http.end_response(res);
    exception
    when utl_http.end_of_body then
    utl_http.end_response(res);
    end;
end;

Now, I needed to change the line req := utl_http.begin_request(url, 'POST',' HTTP/1.1');

I did and worked: req := utl_http.begin_request(url, 'POST');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!