When I send a POST request to my endpoint /api/v1/user/create with the correct post parameters and bearer authorization, it gives a 405 Method Not Allowed. I traced the request to setting the 405 to here in the OptionsAction.php.
if (Yii::$app->getRequest()->getMethod() !== 'OPTIONS') {
Yii::$app->getResponse()->setStatusCode(405);
}
I don’t understand why I’m getting a 405 when all I want to do is make a POST request. Nothing seems to do the trick. I have attempted to add in the CORS filter to my controller, but this does not work.
public function behaviors()
{
$behaviors = parent::behaviors();
$auth = $behaviors['authenticator'];
unset($behaviors['authenticator']);
$behaviors['corsFilter'] = [
'class' => Cors::className(),
];
$behaviors['authenticator'] = [
'class' => CompositeAuth::className(),
'authMethods' => [
HttpBearerAuth::className(),
JwtHttpBearerAuth::className(),
],
'except' => ['options']
];
$behaviors[] = [
'class' => ContentNegotiator::className(),
'formats' => [
'application/json' => Response::FORMAT_JSON,
],
];
return $behaviors;
}
I’m not sure how to proceed. GET requests to /api/v1/users/ work just fine, it seems to be POST requests are tripping up. Advice greatly appreciated.