8

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?

1 Answer 1

22

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I was able to get it working with that then using json_decode I was able to turn it into an array. Worked like a charm thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.