Answer the question
In order to leave comments, you need to log in
How to setup cross domain request in Yii2?
Good afternoon!
The essence of the problem of such api on yii2 lies on the api.site.lc domain, and requests come from admin.sitel.lc.
yii controller config:
class UserController extends ActiveController
{
public $modelClass = 'common\models\User';
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className()
];
$behaviors['corsFilter'] = [
'class' => Cors::className()
];
return $behaviors;
}
public function actionTest()
{
echo 111;
}
}
Answer the question
In order to leave comments, you need to log in
Pass the token via header stackoverflow.com/questions/14183025/setting-appli... . BearerAuth gets the token from the header .
Or, as an option, you can configure the return of CORS headers at the web server level so that they do not go to Yii at all enable-cors.org/server.html .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question