在php脚本中访问发布的Json数据

时间:2021-10-02 15:55:14

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:

我正在使用Requests for PHP库将一些json数据发送到另一个PHP脚本(我使用Laravel的Response :: json方法生成json输出:

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.

我需要接收端的脚本(http://mydomain.com/emails/events)来解码和处理json,但是我很难访问它。我设置了一个简单的测试脚本,通过电子邮件向我发送$ _POST的内容,但每次都是空的。

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

What am I doing wrong here?

我在这做错了什么?

1 个解决方案

#1


12  

PHP do not parse Json POST. So you need to get raw post data like this:

PHP不解析Json POST。所以你需要得到这样的原始帖子数据:

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

Info about php php wrappers

关于php php包装器的信息

#1


12  

PHP do not parse Json POST. So you need to get raw post data like this:

PHP不解析Json POST。所以你需要得到这样的原始帖子数据:

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

Info about php php wrappers

关于php php包装器的信息