Ryan Arief
Ryan Arief

Reputation: 1045

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

Upvotes: 2

Views: 394

Answers (1)

Nuriddin Rashidov
Nuriddin Rashidov

Reputation: 966

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

Upvotes: 4

Related Questions