我可以休息API。使用PUT请求更新数据
http://train-basic/stations/21?name=tt
尝试获取数据:
$request = Yii::$app->request;
$request = $request->post();
$name = $request["name"];
dump($name);
结果,我得到空值。如何解决?
答案 0 :(得分:0)
从PUT下载数据,如POST
$request = Yii::$app->request;
$id = $request->get('id');
$name = $request->get('name');
$days = $request->get('days');
答案 1 :(得分:0)
要获取通过PUT
或PATCH
请求在请求正文中发送的数据,您应该使用getBodyParam()
或getBodyParams()
$request = Yii::$app->request; // returns all parameters $params = $request->getBodyParams(); // returns the parameter "id" $param = $request->getBodyParam('id');
https://www.yiiframework.com/doc/guide/2.0/en/runtime-requests#request-parameters