简体   繁体   中英

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..

You should disbale csrf verification Eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM