开发api接口,做了HttpBearerAuth授权登陆之后,ajax请求跨域,我的配置如下:
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
// 授权验证
'authenticator' => [
'class' => HttpBearerAuth::className(),
'optional' => [
'login',
'signup',
],
],
'corsFilter' => [
'class' => \yii\filters\Cors::className(),
'cors' => [
'Origin' => ['*'],
'Access-Control-Request-Headers' => ['authorization'],
],
],
]);
}
Ajax请求出现:Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ ;
请路过的兄弟姐妹们看看要如何配置才会不会跨域,
‘Origin’ => [‘*’], * 指定可以跨域的域名即可。
use yii\filters\Cors;
`
`