我已经搜索过这个问题的答案,但似乎找不到任何解决方案。
我正在尝试从我的应用程序正在使用的 api 服务获取响应。
对于每笔成功的交易,API 都会将 POST 通知推送到我提供的包含交易详细信息的任何 URL。我发现只有获取请求才会通过。但是,如果我通过公共文件夹路由请求,它似乎工作正常。
有没有办法在 laravel 中使用 POST 路由控制器让 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
}
}
Run Code Online (Sandbox Code Playgroud)
路线/web.php
Route::post('/recieve', 'ApiController@recieve_payment');
Run Code Online (Sandbox Code Playgroud)