Yii 2.0 配置 corsFilter 跨域无效 [ 2.0 版本 ]
根据类参考手册 https://www.yiichina.com/doc/api/2.0/yii-filters-cors
设置了 corsFilter
,但是依然无效,浏览器显示 CORS missing allow origin
两台电脑都是 basic 模板,A 电脑调用 B 电脑 API 的。
public function behaviors()
{
return [
'corsFilter'=>[
'class' => Cors::className(),
'cors' => [
// restrict access to
'Origin' => ['http://www.abc.com', 'http://account.abc.com'],
// Allow only POST and PUT methods
'Access-Control-Request-Method' => ['POST'],
// Allow only headers 'X-Wsse'
'Access-Control-Request-Headers' => ['X-Wsse'],
// Allow credentials (cookies, authorization headers, etc.) to be exposed to the browser
'Access-Control-Allow-Credentials' => true,
// Allow OPTIONS caching
'Access-Control-Max-Age' => 3600,
// Allow the X-Pagination-Current-Page header to be exposed to the browser.
'Access-Control-Expose-Headers' => ['X-Pagination-Current-Page'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => [],// 此处内容过多,发布到yiichina.com时我删掉了
'allow' => true,
],
[
'actions' => [],// 此处内容过多,发布到yiichina.com时我删掉了
'allow' => true,
'roles' => ['?'],
],
[
'actions' => [],// 此处内容过多,发布到yiichina.com时我删掉了
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'signout' => ['post'],
// 'checkid' => ['post'],
],
],
];
}
醉挽清风 补充于 2021-04-01 23:51
同时也有 access
和 verbs
应该不影响吧?
共 4 个回答
醉挽清风 南京
注册时间:2018-07-03
最后登录:2022-09-06
在线时长:15小时38分
最后登录:2022-09-06
在线时长:15小时38分
- 粉丝1
- 金钱180
- 威望10
- 积分430