Access published json data in php script

I am using the Requests for PHP library to POST some json data for another PHP script (I am using Laravel Response :: json to generate 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 a host-side script ( http://mydomain.com/emails/events ) to decode and process json, but I have a hard time accessing it. I am setting up a simple test script that sends me the contents of $ _POST, but every time it becomes empty.

 $post_data = print_r($_POST,true); mail(" my@email.com ","post data",$post_data); 

What am I doing wrong here?

+7
source share
1 answer

PHP does not parse Json POST. So you need to get the raw data:

 $data = file_get_contents("php://input"); 

Php php wrappers info

+12
source

All Articles