Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing posted Json data in php script

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?

like image 457
Yev Avatar asked Jun 01 '13 01:06

Yev


1 Answers

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

like image 148
sectus Avatar answered Oct 16 '22 06:10

sectus