错误使用“访问控制允许来源”,当我有“访问控制允许来源:*”
我有错误:错误使用“访问控制允许来源”,当我有“访问控制允许来源:*”
XMLHttpRequest cannot load http://localhost:5984/cp_config/ . A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin ' http://localhost ' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.
但我有头:
res.header("Access-Control-Allow-Origin", "*");
我该如何解决这个问题?
您可以通过让http://localhost:5984/cp_config/
的服务器端代码响应Origin
请求标头值到Access-Control-Allow-Origin
响应标头值来解决此问题。
有关错误原因的详细信息,请参阅MDN上的“Credentialed requests and wildcards”。
您是怎样呼应进入Access-Control-Allow-Origin
响应标头值的Origin
请求标头值取决于什么样的Web服务器和服务器端编程环境(如果有的话)用于投放http://localhost:5984/cp_config/
。
有一些Web服务器和编程环境具有良好的CORS库,这使得它非常容易实现,并且还有一些其他人喜欢Apache,它几乎不可能独立用于启用CORS的内容交付还增加了一些Python的东西或PHP或任何其他的东西,以允许访问所需的标题值。
你可以尝试添加该处理web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
打开浏览器,调试器和网络面板检查响应头中包含访问控制允许来源:* –