【问题标题】:Allow to get POST data from outter server YII2允许从外部服务器 YII2 获取 POST 数据
【发布时间】:2015-12-08 09:02:17
【问题描述】:

我想创建一个yii2 路由,它可以接收来自其他服务器的 POST 数据(当然我知道所有风险)。

我试着像往常一样发送它,但我收到了这个错误消息。

Error 400

Unable to verify your data submission. 

差不多就是这样……

public function actionWriteSession()
{   
    if (isset($_POST))
    {
        print_r($_POST);
        ...
        write to session
        ...
    }
    ...
}

有什么建议吗?

谢谢..

【问题讨论】:

  • 您能否提供更多您想要的信息,以及您的代码。
  • 是的,ebst 建议,请在询问之前提供一些代码
  • 你应该像 $this->enableCsrfValidation=false 一样禁用控制器的 csrf 验证;
  • Nuriddin Rashidov,非常感谢您,.. 它有效..

标签: yii2 cross-server


【解决方案1】:

你应该禁用 csrf 验证 例如:

$this->enableCsrfValidation=false;//In your controller context

// Or if you only use this action for sending post from outer server
// you can disbalecsrf token verification only this action. So, in your controller

public function beforeAction($action)
{            
    if ($action->id == 'writeSession') {
        Yii::$app->controller->enableCsrfValidation = false;
    }

    return parent::beforeAction($action);
}

【讨论】:

  • 一点也不;)。 @Ryan Arief
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-20
  • 2020-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多