【发布时间】:2019-01-16 16:57:35
【问题描述】:
我有一个公开一些资源的服务器,并发送回以下标头:
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
这是必需的,因为服务器包含静态资源,这些资源可以被我们整个 Intranet 中的各种 webapps 和开发环境访问,它们都是不同的来源。
这直到最近才正常工作,但现在停止了。现在,如果我们尝试从任何来源访问任何资源,我们会收到错误消息:
Failed to load http://foo/bar/res: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://devenv06:4589' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute
所以,我尝试手动添加我的来源,如下所示:
Access-Control-Allow-Origin: http://devenv01,http://devenv02,http://prodserver
Access-Control-Allow-Credentials: true
但现在我收到错误消息:
Failed to load http://foo/bar/res: The 'Access-Control-Allow-Origin' header contains multiple values, but only one is allowed
这基本上使服务器无法使用,因为我需要多个来源。
所以,我想知道的是:
- 这是浏览器引入的新功能,还是服务器上发生了一些变化?为什么它以前使用该配置可以工作,而现在却不行? (客户端代码没有改变...)
- 是否有一个通用的解决方案,而不必手动设置每个可能的原点?
【问题讨论】:
标签: cors