POST request giving a 405 from OPTIONS

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.

check your routing at main.php UrlManager you have to allow POST

'POST v1/user/create' => 'user/create',

Or better


                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => 'v1/user',
                    'only' => ['index', 'create', 'update'],
                    'pluralize' => false
                ],

more details:

https://www.yiiframework.com/doc/guide/2.0/en/rest-routing