我正在使用Laravel-5.5,我正在为一个iOS应用程序开发一个app。
在这里,我使用postman来调用所有apis。我有一个带有两个头的注册api:
1) Authorization: Bearer access_token
2) Content-type: application/x-www-form-urlencoded
现在,当我请求这个api时,我只想打印dd($request->all());,但它没有给我适当的请求数据。我尝试过json_decode(urldecode(file_get_contents('php://input')));来解码它,也尝试过$request->getContent();,但是没有运气!
当使用Content-type: application/x-www-form-urlencoded时,有人知道如何在控制器中获取请求数据吗??
编辑:
public function registration(Request $request)
{
dd($request->all());
dd($request->getContent()); //also tried but not work
dd(json_decode(urldecode(file_get_contents('php://input')))); //no luck
}发布于 2018-04-25 13:50:02
我把它修好了:
$requestData = json_decode($request->getContent(), true);
dd($requestData);在邮递员中传递标题Content-Type: application/json,它是固定的!
你只需要这样做:
$requestData = json_decode($request->getContent(), true);您可以在请求中的控制器中获取所有请求数据!
希望这将有助于任何用户在未来!
https://stackoverflow.com/questions/49993967
复制相似问题