我使用 FOSRestBundle 和 Nelmio Cors Bundle 并且有一些端点,/api/name_end_points 我需要一些服务器有权调用这个端点。现在我在控制台中遇到错误
XMLHttpRequest cannot load http://mydomain.com.com/api/endpoint?value=test&value1=test. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:3000' is therefore not allowed access.
这是我的配置:
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json : true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
routing_loader:
default_format: json
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: ['*']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
max_age: 3600
如果我想为我的端点访问某些服务器,如何更正配置 NelmioCorsBundle ?喜欢这个
allow_origin: ['*aog.jobs*', '*localhost*']
并删除了默认值?
您需要
通过将Origin
请求标头的值复制到Access-Control-Allow-Origin
响应标头中(而不是硬编码*
)来明确声明允许源(如Origin
请求标头中指定)访问资源。
在这样做之前,请非常确定要使其全局可访问(或对 Origin
标头的值执行测试以确保它正常)。