D
D
Dmitry2015-10-13 23:32:09
Yii
Dmitry, 2015-10-13 23:32:09

How to accept data using POST method in Yii2?

You need to get data from another site using the POST method.
Immediately after redirecting to my site from an external site, I get a Bad Request error (# 400).
If you call the controller directly, then there are no errors.
Disabling CSRF didn't help either.
Tell me, please, what could be the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-10-14
@1diem

That's more correct
you can pass in the header with the name X-CSRF-Token if AJAX
or disable the check in the controller (not recommended)

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

    return parent::beforeAction($action);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question