Laravel file_get_contents('php://input') 不起作用



我已经在此问题上搜索了答案,但我似乎找不到任何解决方案。
我正在尝试从API服务中获得响应,我的应用程序正在消耗。
在每笔成功的交易中,API将向我提供的任何URL推出通知,并提供交易的详细信息。我发现只有得到请求。但是,如果我通过公共文件夹将请求路由,它似乎可以正常工作。
有什么方法可以使用laravel中的Post Route Controller获得File_get_contents('php://input')工作?
这是我的代码的示例:

apicontroller.php

public function recieve_payment(Request $request){
    $res = file_get_contents('php://input');
    if (!empty($res)) {
        // insert values of $res to database
    }
}

路由/web.php

Route::post('/recieve', 'ApiController@recieve_payment');

使用 $request->getContent()

laracast。

我认为将URI排除在CSRF Protection

之外
protected $except = [
    'stripe/*',
];

那小块代码从字面上节省了我的时间。

将路由放在路由/api.php中,而不是路由/web.php。路由/api.php已禁用CSRF。

路由/api.php

Route::post('/recieve', 'ApiController@recieve_payment');

您的Webhook URL现在将是:

base_url/api/recection

另外,您无需使用:

$res = file_get_contents('php://input');

您可以使用:

$res = $request->all();

最新更新