超薄3如何获得Post mothod身体(Slim 3 How to get the Post mothod body)

编程入门 行业动态 更新时间:2024-10-11 01:14:36
超薄3如何获得Post mothod身体(Slim 3 How to get the Post mothod body)

我使用表单数据 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.

更多推荐

本文发布于:2023-07-17 15:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1146363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   身体   Post   mothod   Slim

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!