【问题标题】:Why is the empty POST in YII2 after reinstallation?为什么YII2重装后POST是空的?
【发布时间】:2020-05-20 10:17:06
【问题描述】:

我们为移动应用开发了自己的api,它基于post请求工作,但是在新服务器上重新安装项目后,Yii :: $ app-> request-> post()总是返回一个空值。同时,Yii::$app->request->getRawBody() 包含了一个值,但是我不想重写所有的api。

告诉我可能是什么问题以及采用哪种方法进行挖掘?提前致谢。

通过移动应用程序发送或通过 RestClient PHPStorm 发布。总是返回空虚。

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::class,
            'only' => ['logout', 'signup'],
            'rules' => [
                [
                    'actions' => ['login'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
                [
                    'actions' => ['login'],
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
        'verbs' => [
            'class' => VerbFilter::class,
            'actions' => [
                'login' => ['post', 'get'],
                'token' => ['post', 'get'],
                'logout' => ['post', 'get'],
            ],
        ],
    ];
}

public function beforeAction($action) {
    $this->enableCsrfValidation = false;
    return parent::beforeAction($action);
}

public function actionLogin()
{
    return Yii::$app->request->post("username");
}

【问题讨论】:

    标签: php apache nginx web yii2


    【解决方案1】:

    可能是您的请求是通过 get() 方法

    $app->request->get();
    

    【讨论】:

    • 不!我发送了 POST 请求!
    • 你检查过 $_POST 的真实内容吗?试试 var_dump($_POST) .. 告诉我
    【解决方案2】:

    重新安装项目后,问题自行解决。谢谢大家。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 2013-12-19
      • 1970-01-01
      • 2014-10-13
      相关资源
      最近更新 更多