我使用表单数据 id = 1发布帖子并使用getparams方法,如$request->getParams('id')我得到了id。
现在我通过Json进行查询
POST localhost / books_example / public / apiv1
身体是:
{“id”:“1”}
这里$request->getParams('id') , $request->getParams()和$request->getBody()都不起作用。 现在,我怎样才能获得id参数?
I make a post using form data id = 1 and use getparams method like this $request->getParams('id') i get the id.
Now i make a query via Json
POST localhost/books_example/public/apiv1
Body is:
{"id": "1"}
Here $request->getParams('id') , $request->getParams() and $request->getBody() are not work. Now, how can i get the id parameter?
最满意答案
从php://input获取请求体并将其传递给json_decode() 。
$data = json_decode(file_get_contents('php://input'));您要查找的值将是$data->id 。
Get the request body from php://input and pass it to json_decode().
$data = json_decode(file_get_contents('php://input'));The value you are looking for will be in $data->id.
更多推荐
发布评论