Call a POST webservice in Oracle APEX AJAX On demand process

时间:2019-01-07 13:05:31

标签: rest oracle-apex

I have created a POST restful webservice in ORAcle APEX. I want to consume this webservice in my AJAX On demand Process. How can I do that. The POST webservice does a simple insert into a table.

I tried writing the below code, but it doesn't work. It gives an error :" Unexpected token s in JSON at position 0".

            declare
             l_clob clob;
            begin

            apex_web_service.g_request_headers(1).name := 'Content-Type';
            apex_web_service.g_request_headers(1).value := 'application/x-www-form-urlencoded'; 

            l_clob := apex_web_service.make_rest_request(
                          p_url => 'https://ofdapex.antwerpen.be/ords/xxua_apex/test/test/',
                          p_http_method => 'POST',
                          p_parm_name => apex_util.string_to_table('DESCRIPTION'),
                          p_parm_value => apex_util.string_to_table(apex_application.g_x01));

            apex_json.open_object;  
                    apex_json.write('success', false);  
                    apex_json.write('v_result', v_user_name);
                    apex_json.close_object; 

            end;

I believe that there is something that I am missing after assigning value in the l_clob. But I am not sure what.

Can somebody please share their knowledege of how to call POST webservice inside of AJAX in oracle APEX.

Thanks.

1 个答案:

答案 0 :(得分:0)

由于使用的是HTTPS,因此可能需要提供Oracle Wallet路径。

v_response := apex_web_service.make_rest_request(
    p_url => 'https://ws.example.com/test/send'  -- example
    ,p_body => v_clob                
    ,p_http_method => 'POST'
    ,p_wallet_path => 'file:$ORACLE_HOME/appsutil/wallet'  -- example
    ,p_https_host => 'ws.example.com'    -- example
    );