0

I have been struggling with the following problem for few days. I am expected to receive POST data from a third party company for certain real time events. I have been in contact with them as to why my script isn't seeing anything. Unfortunately, they are less then helpful and just tell me "it works for everybody else".

I setup a simple PHP script after doing some research on the web but it always shows no post data. This isn't my area of expertise so I may be missing something obvious.

Here is the only documentation they give: This API will send a real-time http request upon every successful event with all of the conversion data. The data is sent via an http POST method, and the data is JSON formatted.

This is my script which for now is trying to just log it to a file. The file is created and I see the IP address of the request but the output is empty in terms of post data.

    ob_start();
    echo "Request from :" . $_SERVER[REMOTE_ADDR];
    echo "print_r:".print_r($_POST,true);
    if(array_key_exists('app_id', $_POST))// me attempting to access a specific key they claim is in the post data
    {
      echo "app id = " . $_POST['app_id'];
    }
    //I also tried both of these and neither output anything
    //foreach ($_POST as $key => $value) //idea 1
    foreach($_POST as $item) //idea 2
    {
        //echo "key=".$key." value=".$value; //idea 1 log
        echo "next=";//idea 2 log
        echo $item;
    }
    $contents = ob_get_flush();
    file_put_contents("log.txt",$contents,FILE_APPEND);
Rayhan Muktader
  • 2,038
  • 2
  • 15
  • 32
user2292539
  • 245
  • 1
  • 11

1 Answers1

1

There's not a lot to go on here -- who knows what the client is actually sending -- but here's a thought:

POST is just an HTTP command. It's traditional for the body of a POST to be a series of key-value pairs from a form, but it is not actually necessary. It's possible that the remote client is issuing a POST request to your server and then just delivering a JSON blob in the request body, which would not be successfully parsed into the $_POST array.

I recommend exploring the answer at How to get body of a POST in php? to see if that helps shed light on this problem.

Community
  • 1
  • 1
Tim Pierce
  • 5,514
  • 1
  • 15
  • 31