Forum Stats

  • 3,782,431 Users
  • 2,254,644 Discussions
  • 7,880,078 Comments

Discussions

Submit to external PHP with POSTed parameters!

Mahmoud_Rabie
Mahmoud_Rabie Cloud Solution Architect,Member Posts: 3,216 Bronze Crown
edited Nov 27, 2017 1:28AM in APEX Discussions

Hello,

I hope all of you are doing fine.

Given:

- Sender: Apex Application needs to submit sensitivedata to external reciever PHP page

- Reciever: PHP page with $_POST['sensitivedata']

Required:

- How to submit to the receiver PHP page with POSTed sensitivedata?

- A demo would be preferred.

Old Resource

I have found this old resource. However, I think there is a better and a newer way to do that.

Send HTML data with the POST method from APEX | APEX-AT-WORK by Tobias Arnhold

I would appreciate any help you provide.

Regards

Mahmoud

Tagged:

Answers

  • Pavel_p
    Pavel_p Member Posts: 2,312 Gold Trophy
    edited Nov 24, 2017 12:59PM

    Hi Mahmoud,

    hope you're doing well too.

    No matter if it's a php page, any other page or no page at all, it can be considered as a REST service and thus treated as such (e.g. nothing else than a normal http request-response). So you can invoke it using apex_web_service.make_rest_request and specify the POST method (which is the only information you have provided so far). Now you should be more specific if the page expects the data in the request body (and if so, in what format), url, form-encoded...whatever.

    Regards,

    Pavel

    edit: any chance the page can be accessed from internet?

  • Mahmoud_Rabie
    Mahmoud_Rabie Cloud Solution Architect, Member Posts: 3,216 Bronze Crown
    edited Nov 24, 2017 1:18PM

    Hi Pavel,

    any chance the page can be accessed from internet?

    The PHP receiver page contains a form that should be filled and posted to a third page.  Yes, it should be accessed from the internet.  I need to submit, redirect or goto that PHP page from Apex.

    I think apex_web_service.make_rest_request would not be enough for that.

    Now, I am looking at this thread. I don't know if it could help or not.

    Regards

    Mahmoud

  • Pavel_p
    Pavel_p Member Posts: 2,312 Gold Trophy
    edited Nov 24, 2017 6:10PM

    Sorry, I see no relation between your original requirement and the thread you posted. I believe you should be able to mimic almost any http call with apex_web_service.make_rest_request, so I would suggest to try something like

    declare  l_resp_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_resp_clob := apex_web_service.make_rest_request(    p_url => 'your_php_url',    p_http_method => 'POST',    p_parm_name => 'sensitivedata',    p_parm_value => 'sensitive_data_content');--check the response code  if apex_web_service.g_status_code = 200 --200 OK    apex_debug.message('looks promising');  else    apex_debug.message('too bad, something went wrong, response code is %s', apex_web_service.g_status_code );  end if;    apex_debug.message('response is: %s', dbms_lob.substr(l_resp_clob,32767)); --print max length of varchar2 end;

    however this is more or less a shot in the dark, I just have a feeling it could work this way. Give it a try and you'll see what happens.

  • Mahmoud_Rabie
    Mahmoud_Rabie Cloud Solution Architect, Member Posts: 3,216 Bronze Crown
    edited Nov 24, 2017 3:59PM

    Pavel,

    Thanks a lot for your interest and effort.

    Suppose we have three pages:

    1) Apex Page that would submit the sensitive data extracted from the Apex Application.

    2) External and Independent PHP page (let's call it first.php) contains code like this :

    <html>    <head>        <meta charset="UTF-8">        <?php            $sensitivedata = $_POST['sensitivedata'];            ....            ..        ?>        </head>    <body>       <form class="checkout" accept-charset="UTF-8" action="second.php" method="POST">            <input type="hidden" name="sensitivedata" value="<?php echo $sensitivedata ?>" />            <input ..            <input ..            <input ..                     <input type="submit" value="SubmitSensitiveDataAndOtherInputs">        </form>    </body></html>

    3) second.php that would go away from the Apex context

    If I am not wrong, I think your code is used to POST data and get response not to redirect or submit posted data to an external PHP that would be used and filled by the user through the browser.

    My questions are:

    - How to employ your code in Apex page to submit or redirect from Apex page to first.php (to display first.php in the browser completely outside apex context)?

    - Could you please provide a demo

    - Could we use apex.submit to do the task or it is working only with internal apex pages? Let's ask Paul @fac586

    - What about using $.post or jQuery to post data and submit or redirect to a first.php when a button is pressed in the Apex page?

    Regards

    Mahmoud

  • Mahmoud_Rabie
    Mahmoud_Rabie Cloud Solution Architect, Member Posts: 3,216 Bronze Crown
    edited Nov 25, 2017 5:32AM
  • Pavel_p
    Pavel_p Member Posts: 2,312 Gold Trophy
    edited Nov 25, 2017 9:28AM

    Hi Mahmoud,

    originally I thought that you want to invoke the page first.php and process the response, but this seems to be more complicated and I must admin that I have no idea whatsoever how this could be done, in fact I'm not even sure if I understand the problem. Hopefully others can help...

    Regards,

    Pavel

  • Mahmoud_Rabie
    Mahmoud_Rabie Cloud Solution Architect, Member Posts: 3,216 Bronze Crown
    edited Nov 27, 2017 1:28AM
    originally I thought that you want to invoke the page first.php and process the response, but this seems to be more complicated

    Yes, exactly. It is more complicated. I should submit sensitive data using POST method to that external PHP page. Even I don't know if this old thread could help or not

    Send HTML data with the POST method from APEX | APEX-AT-WORK by Tobias Arnhold

    If it could help, is there a modern approach?

This discussion has been closed.