I'm using the Requests for PHP library to POST some json data to another PHP script (I'm using Laravel's Response::json method to generate the json output:
public function postIndex()
{
$input = Input::get();
$data = Response::json($input);
$url = 'http://mydomain.com/emails/events';
$response = Requests::post($url, array('Content-Type' => 'application/json'), $data);
return $response->status_code;
}
I need the script on the receiving end (http://mydomain.com/emails/events) to decode and process the json, but I'm having a hard time accessing it. I setup a simple test script that emails me the contents of $_POST, but it comes up empty every time.
$post_data = print_r($_POST,true);
mail("[email protected]","post data",$post_data);
What am I doing wrong here?
PHP do not parse Json POST. So you need to get raw post data like this:
$data = file_get_contents("php://input");
Info about php php wrappers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With