繁体   English   中英

CORS 适用于 chrome 但不适用于 firefox、angularjs

[英]CORS works in chrome but not firefox, angularjs

我正在尝试将 angularJS 与 Jetty 后端一起使用。

预检 CORS 请求在 chrome 中工作正常,但在 Firefox 中我收到此 CORS 错误:跨源请求被阻止:同源策略不允许在http://remote.machine:8080/api/v1/provisioning/users读取远程资源/当前用户 这可以通过将资源移动到同一域或启用 CORS 来解决。

选项请求的标头如下:

HTTP/1.1 200 OK
Date: Wed, 24 Sep 2014 16:06:12 GMT
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-Frame-Options: DENY
Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE
Access-Control-Max-Age: 3600
Access-Control-Allow-Headers: Access-Control-Allow-Headers: Origin, Authorization, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Credentials: true
Set-Cookie: JSESSIONID=eyv8cpnnfphy1b0121uzt293y;Path=/
Content-Length: 0
Server: Jetty(9.2.2.v20140723)

角度请求设置如下:

$http.get(AS_API_URL + '/provisioning/users/current-user', {
            headers: {
                'Authorization': 'Basic ' + base64EncodedAuth               
            }
        });

出于某种原因,这些标头在 Chrome 中可以正常工作,但在 Firefox 中不能正常工作,有人知道为什么吗? 我需要提供更多信息吗?

编辑:

Musa 关于 Access-Control-Allow-Headers 格式错误的说法是正确的。 我编辑了 Jetty 服务器,所以标题现在显示为:

Access-Control-Allow-Headers: Origin, Authorization, X-Requested-With, Content-Type, Accept

我感谢你 Musa,你拯救了我的一天 :)

为了扩展 Musa 在评论中的回答,Firefox 阻止了请求,因为以下标头有两次而不是一次:

Access-Control-Allow-Headers: Access-Control-Allow-Headers: Origin, Authorization, X-Requested-With, Content-Type, Accept

应该改为

Access-Control-Allow-Headers: Origin, Authorization, X-Requested-With, Content-Type, Accept

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM