How to post data using URL from plsql

sakthikumar
sakthikumar used Ask the Experts™
on
Hi,

Below is the service in which I want to access the post method from plsql.

https://apex.oraclecorp.com/pls/apex/training_app_dev/seaashm/keyevent

the service does have four parameters. How do I call the service from plsql passing all the parameters.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2018
Commented:
You need to use UTL_HTTP:

      req   UTL_HTTP.REQ;
      resp  UTL_HTTP.RESP;

Open in new window


then create your post body:

postBody := 'parama='|| parama ||'&paramb='|| paramb ||'&paramc='||paramc || '&paramd=' || paramd;

Open in new window


Once you have your postBody you can do:

req := utl_http.begin_request('https://apex.oraclecorp.com/pls/apex/training_app_dev/seaashm/keyevent', 'POST',' HTTP/1.1');
 utl_http.set_header(req, 'user-agent', 'mozilla/4.0'); 
utl_http.set_header(req, 'content-type', 'application/x-www-form-urlencoded'); 
utl_http.set_header(req, 'Content-Length', length(postBody));
          
utl_http.write_text(req, postBody);

resp := utl_http.get_response(req);

            begin
                loop
                    utl_http.read_line(resp, buffer);
                end loop;
               utl_http.end_response(resp);
                exception
                when utl_http.end_of_body then
                    utl_http.end_response(resp);
                end;

Open in new window

Distinguished Expert 2018

Commented:
I gave a perfectly correct answer, so I object to the deletion of this question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial