-
-
Notifications
You must be signed in to change notification settings - Fork 23
slim Invalid setting #8
Comments
origins 添加你需要跨域的域,测试可以添加 例如: $config = [
'allow-credentials' => false, // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
'allow-headers' => ['*'], // ex: Content-Type, Accept, X-Requested-With
'expose-headers' => [],
'origins' => ['*'], // 允许跨域只添加 * 即可
'methods' => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
'max-age' => 0,
];
$app->add(new Medz\Cors\Slim\Cors($config)); |
还是遇到了问题,而且就算是我在nginx也设置一下允许跨域,也是会报错:Failed to load http://wx.simplesay.xin/user/index: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. |
@sunyinggang 好的,我再测试一下回复你~ |
有没有测试通过呀 |
这是我写给你的 Slim 框架继承 Cors 例子,包含了跨域测试,解压后请阅读 |
感谢您的帮助,现在有效了,问题是我的new \Medz\Cors\Slim\Cors($setting),我没有附带第二个参数true,我发现如果去掉这个参数,就会无效,但是我在您的官方文档中并没有看到对这个的解释,是不是以后使用的时候默认都得带上这个参数,或者在官方实例中改为带第二参数的这种形式,会比较好 |
@sunyinggang |
In my slim project,Still reporting an error:No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.
My setting:
$set = [
'allow-credentials' => false, // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
'allow-headers' => [''], // ex: Content-Type, Accept, X-Requested-With
'expose-headers' => [],
'origins' => [''], // ex: http://localhost
'methods' => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
'max-age' => 0,
];
$app->add(new Medz\Cors\Slim\Cors($set));
The text was updated successfully, but these errors were encountered: