yii2cross-server

Allow to get POST data from outter server YII2


i want to make a yii2 route which can receive POST data from other server (of course i know about all risk).

I tried to just send it like usual but i got this error message.

Error 400

Unable to verify your data submission. 

more or less is just like this...

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

Any Advice?

Thanks..


Solution

  • You should disbale csrf verification E.g:

    $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);
    }