-2

I’m trying to make a POST request via Guzzle to a Yii controller but getting a "Bad Request #400". I thought when I don’t use behaviours() the controller is automatically accessible to all kinds of requests, but nope. How I can solve this? What would be best practice for CURL/Guzzle requests in Yii2?

class ImportController extends yii\web\Controller {
   public function actionIndex() {
      return 'OK';
   }
}
Nimantha
  • 6,405
  • 6
  • 28
  • 69
NicOwen
  • 171
  • 1
  • 3
  • 8

1 Answers1

1

You should create a rest controller instance (yii\rest\ActiveController) and implement authentication for it as described here: https://www.yiiframework.com/doc/guide/2.0/en/rest-authentication

That is probably the correct approach to your use case, and you would not have to deal with CSRF.

dataskills
  • 646
  • 7
  • 15