我有一个Symfony2应用程序,我正在尝试使用Nelmio CORS软件包进行设置。我在apache服务器上运行它(BitNami mampstack)。
无论我做什么,我都会将此错误记录到我的浏览器控制台:
XMLHttpRequest cannot load http://localhost:8000/avrequests. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains the invalid value 'null'. Origin 'http://localhost:8080' is therefore not allowed access.
我的回复标题确实如下所示:
Access-Control-Allow-Origin:null
Cache-Control:no-cache
Connection:close
Content-Type:text/html; charset=UTF-8
Date:Sun, 29 Nov 2015 05:14:13 GMT
Host:localhost:8000
X-Debug-Token:3f40a5
X-Debug-Token-Link:/_profiler/3f40a5
X-Powered-By:PHP/5.5.27
这是我的config.yml文件中的Nelmio配置(它基本上是默认值):
nelmio_cors:
defaults:
allow_credentials: false
allow_origin: []
allow_headers: []
allow_methods: []
expose_headers: []
max_age: 0
hosts: []
origin_regex: false
paths:
'^/':
allow_origin: ['*']
allow_headers: ['origin', 'content-type']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE','OPTIONS']
max_age: 3600
我已经尝试了将这一行添加到httpd.conf文件中的所有内容....
Header set Access-Control-Allow-Origin "*"
...创建.htaccess文件。捆绑包正确地包含在Symfony中的AppKernel.php文件中。什么都行不通;我无法正确设置Access-Control-Allow-Origin标头。