gpt4 book ai didi

rest - Yii2 Rest API PUT方法调用不起作用

转载 作者:行者123 更新时间:2023-12-04 12:18:28 24 4
gpt4 key购买 nike

在我的 Controller 中:

namespace app\api\modules\v1\controllers;

use yii\rest\ActiveController;
use yii\filters\VerbFilter;
use yii\web\Response;

class CountryController extends ActiveController
{
public $modelClass = 'app\models\Country';

public function behaviors()
{
return [
[
'class' => 'yii\filters\ContentNegotiator',
'only' => ['index', 'view','create','update','search'],
'formats' => ['application/json' =>Response::FORMAT_JSON,],

],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index'=>['get'],
'view'=>['get'],
'create'=>['post'],
'update'=>['PUT'],
'delete' => ['delete'],
'deleteall'=>['post'],
'search' => ['get']
],

]
];
}
}`

我从我的POSTMAN应用程序尝试

对于创建,我使用POST http://localhost/myapp/api/v1/countries工作正常。但是对于更新,我使用PUT http://localhost/myapp/api/v1/countries/16返回16记录作为JSON输出,未按预期更新。

哪里错了?谢谢!!

最佳答案

在POSTMAN App中,打开“请求正文”选项卡,然后选择x-www-form-urlencoded而不是form-data。那对我有用。

x-www-form-urlencoded selected

关于rest - Yii2 Rest API PUT方法调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37025353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com