Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法获取使用Yi2 RESTful API的POST_Rest_Post_Methods_Yii2 - Fatal编程技术网

无法获取使用Yi2 RESTful API的POST

无法获取使用Yi2 RESTful API的POST,rest,post,methods,yii2,Rest,Post,Methods,Yii2,我使用ActiveController和Basic身份验证在yii2basic中编写了一个restfulapi。我可以让get方法工作,但是当我尝试使用Postman Chrome扩展的帖子时,它会抛出一个错误,说“methodnotallowed。这个url只能处理以下请求方法:get,HEAD.” 我是否需要在web服务器上配置任何东西来测试此功能,或者需要控制器中的其他功能?我甚至用一个包含两列的非常简单的表尝试了这一点,并且还将列设置为安全的,正如在另一个问题中所暗示的那样 感谢您在这方

我使用ActiveController和Basic身份验证在yii2basic中编写了一个restfulapi。我可以让get方法工作,但是当我尝试使用Postman Chrome扩展的帖子时,它会抛出一个错误,说“methodnotallowed。这个url只能处理以下请求方法:get,HEAD.”

我是否需要在web服务器上配置任何东西来测试此功能,或者需要控制器中的其他功能?我甚至用一个包含两列的非常简单的表尝试了这一点,并且还将列设置为安全的,正如在另一个问题中所暗示的那样

感谢您在这方面的帮助。以下是我目前的代码:

<?php
namespace app\controllers;

use yii\rest\ActiveController;
use yii\filters\auth\HttpBasicAuth;

class TestController extends ActiveController
{
    public $modelClass = 'app\models\Test';

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => HttpBasicAuth::className(),
        ];
        return $behaviors;
    }
}

尝试明确允许您的操作使用POST方法:

$behaviors['verbs'] = [
                'class' => \yii\filters\VerbFilter::className(),
                'actions' => [
                    'index' => ['post'],
                ],
            ]; 

尝试明确允许您的操作使用POST方法:

$behaviors['verbs'] = [
                'class' => \yii\filters\VerbFilter::className(),
                'actions' => [
                    'index' => ['post'],
                ],
            ]; 

结果我用错了终点。使用这个终点对我来说很有效:


结果证明我使用了错误的终点。使用这个终点对我来说很有效:

试试这个: $params=\Yii::$app->request->post()

供参考: 试试这个: $params=\Yii::$app->request->post()

供参考: