Slim 3 如何获得 Post 方法 body
Slim 3 How to get the Post mothod body
我使用 表单数据 id = 1
创建了一个 post 并使用像这样的 getparams 方法 $request->getParams('id')
我得到了 id。
现在我通过Json
查询
POST localhost/books_example/public/apiv1
Body 是:
{"id": "1"}
这里 $request->getParams('id')
, $request->getParams()
和 $request->getBody()
是行不通的。现在,如何获取 id 参数?
从php://input
获取请求正文并将其传递给json_decode()
。
$data = json_decode(file_get_contents('php://input'));
您要查找的值将在 $data->id
.
中
我使用 表单数据 id = 1
创建了一个 post 并使用像这样的 getparams 方法 $request->getParams('id')
我得到了 id。
现在我通过Json
查询POST localhost/books_example/public/apiv1
Body 是:
{"id": "1"}
这里 $request->getParams('id')
, $request->getParams()
和 $request->getBody()
是行不通的。现在,如何获取 id 参数?
从php://input
获取请求正文并将其传递给json_decode()
。
$data = json_decode(file_get_contents('php://input'));
您要查找的值将在 $data->id
.