【问题标题】:Symfony FosRest and NelmioCors A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin'Symfony FosRest 和 NelmioCors 不能在“Access-Control-Allow-Origin”中使用通配符“*”
【发布时间】:2016-02-10 12:24:59
【问题描述】:

我将 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*']

并删除默认值?

【问题讨论】:

    标签: php symfony fosrestbundle nelmiocorsbundle


    【解决方案1】:

    您需要通过将Origin 请求标头的值复制到@987654323 中来明确声明允许源(在Origin 请求 标头中指定)访问资源@response 标头(而不是硬编码*)。

    在您这样做之前,请确保您希望全世界都可以访问它(或对 Origin 标头的值进行测试以确保它正常)。

    【讨论】:

    • 我不明白,我需要一两台服务器的访问权限为真。示例 - mydomain.com。我需要在 nelmio_cors 的配置中写什么?
    猜你喜欢
    • 2017-01-17
    • 2011-09-02
    • 2018-10-09
    • 2017-03-05
    • 1970-01-01
    • 2016-09-30
    • 2015-06-17
    • 2012-12-09
    相关资源
    最近更新 更多