Bug with rbv_api.sendHttpPost(url, params, headers) - Forum - Rollbase - Progress Community

Bug with rbv_api.sendHttpPost(url, params, headers)

 Forum

Bug with rbv_api.sendHttpPost(url, params, headers)

  • rbv_api.sendHttpPost(url, params, headers)

    when headers = null, it properly posts data to url, if headers are set, it unsets the data in the request (data = null).

    most probably it's a bug

  • I did a test with a random header and it seems to work. Could you give me the exact headers you used?

  • Here is the trigger code:

    [code]

    // base64_encode (client_id:secret)

    var basic_auth_token = "RU9KMlMtWjZPb05fbGVfS1MxZDc1d3NaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA6RUNsdXNNRVVrOGU5aWhJN1pkVkxGNWNaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA=";

    var headers = {
                   "Accept": "application/json",
                   "Accept-Language": "en_US",
                   "Authorization": "Basic " + basic_auth_token
       };
    rbv_api.println("Headers:");
    rbv_api.printArr(headers);
    rbv_api.println("");

    rbv_api.println("Data:");
    var data = {"grant_type": "client_credentials"};
    rbv_api.printArr(data);
    rbv_api.println("");

    var url = "http://mysite.com/test.php";


    var resp = rbv_api.sendHttpPost(url, data, headers);

    rbv_api.println("Response:");
    rbv_api.printArr(resp);
    rbv_api.println("");

    [/code]

    test.php code:

    [code]

    <?php

    print_r($_SERVER);

    print_r($_POST);

    ?>

    [/code]

    If we send the above headers, we get empty _POST array in the php script.

    If we send headers=null, we get _POST array properly.

  • Any news on this please? We need this bug fixed so that we can complete our creation of a Paypal payment Object using their REST API

  • Apologies, for some reason I wasn't notified of your response (or missed the notification).

    Either way, is the PHP code only the two lines you're showing? When I try to use your code I get "Error  Upload failed, response=Not Acceptable" (whether the headers passed are null or not)

  • Have you changed the URL to your appropriate test.php file location?

    var url = "mysite.com/test.php";

  • Yes I did. I made sure that the test.php file had the exact same content as you.

  • test.php content can be:

    <?php

    print "<h1>POSTED DATA:</h1><br /><pre>";

    print_r($_POST);

    print "</pre>";

    print "<h1>SERVER VARS (headers and others)</h1><br /><pre>";

    print_r($_SERVER);

    print "</pre>";

    ?>

    After that, change url in the trigger javascript to the actual url of test.php on your server.

    Please let me know if that helps you re-produce the issue. Also, what version of RB are you testing on?

  • We seem to be having the same issue on RB v2.0.4 so it seems it is still an outstanding bug

  • I tried with both Rollbase Hosted Cloud (so 2.0.0.4) and Private Cloud 2.0.0.3. And I doubt that the second version of the PHP code changes anything, as all it does is to print extra HTML. The error I get seems to be HTTP error 406, which means I'll try to pass some headers typically passed by a web browser.

  • By the way, what trigger type are you using to run the JavaScript code? The type shouldn't matter, but one never knows.

  • Here is a test that I performed and that seems to work even with headers:

    var url = "hroch486.icpf.cas.cz/.../echo.pl";

    var params = { "your_name": "This is a test" }

    var headers = { "Accept": "text/html" }

    var resp = rbv_api.sendHttpPost(url, params, headers);

    I created an Object Script type of trigger and tested the code using the Debug Formula. Whether I use headers or not (or even your headers) I get a response.

    Don't get me wrong, I am not saying there is no bug in Rollbase. But if there is, it seems to be more than just the lack of headers.

  • We use Object Script type of triggers and test it using the Debug Formula.

    We have just realized that  sendHttpPost() sends "Content-Type: multipart/form-data" header.

    Is it possible to change it to "Content-Type: application/x-www-form-urlencoded"?

    Our aim is to implement PayPal Rest API, for example:

    curl -v https://api.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json"  -H "Accept-Language: en_US"   -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp"  -d "grant_type=client_credentials"

    If we send "Content-Type: multipart/form-data" via curl to PayPal, we get "415 Unsupported Media Type" error i.e. the same error in Rollbase.

    curl -v https://api.sandbox.paypal.com/v1/oauth2/token  -H "Accept: application/json"  -H "Accept-Language: en_US"  -H "Content-Type: multipart/form-data"  -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp"  -d "grant_type=client_credentials"

    We suspect Rollbase doesn't take into account "Content-Type" header and incorrectly performs the request i.e. it sends data as multipart anyway.

    var headers = {
                   "Accept": "application/json",
                   "Accept-Language": "en_US",
                   "Content-Type": "application/x-www-form-urlencoded",
                   "Authorization": "Basic " + basic_auth_token
       };

  • You can use trigger of type "Send HTTP POST Request" and here select Encoding as URL to set Content Type as application/x-www-form-urlencoded

  • It seems there is another issue with "Send HTTP POST Request" type of trigger, it doesn't fill in the "Content-Length" header in the request.

    <title>411 Length Required</title>

    </head><body>

    <h1>Length Required</h1>

    <p>A request of the requested method POST requires a valid Content-length.<br />

    ...

    Anyway we need to a logic to perform several POST requests so we think  "Send HTTP POST Request" type of trigger won't work for us.