我正在尝试向使用 session key 进行授权的外部应用程序服务器发送简单的 CORS 请求。
$.ajax({
type: "GET",
url: "https://192.168.1.72:8442/api/file/",
headers: {"Authorization": "3238562439e44fcab4036a24a1e6b0fb"}
});
它在 Firefox 18、Opera 12.12 和 Rekonq 2.0(也使用 WebKit)中工作正常,但在 Google Chrome 中不起作用(尝试过版本 21 和 24)。在 Google Chrome 中,它显示选项资源无法在网络检查器中加载,并且应用程序服务器没有收到任何请求。我尝试过 jQuery 1.8.3 和 1.9.0。
Request URL:https://192.168.1.72:8442/api/file/
Request Headers
Access-Control-Request-Headers:accept, authorization, origin
Access-Control-Request-Method:GET
Cache-Control:no-cache
Origin:https://192.168.1.72:8480
Pragma:no-cache
如果我从请求中删除 header ,那么我也会在 Google Chrome 中收到 401,并且在应用程序服务器上禁用授权的情况下它能够访问资源。发送哪些 header 并不重要。我能够发送的唯一 header 是 {"Content-Type": "plain/text"}。所有其他 header 名称/值在 Google Chrome 中都会出错,但在我上面提到的所有浏览器中都可以工作。
为什么 Google Chrome 不处理 CORS 请求中的 header ?
最佳答案
这是 Google Chrome 中的一个错误:http://code.google.com/p/chromium/issues/detail?id=96007 .
关于jquery - 仅当有 header 时,CORS 请求才会在 Chrome 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14492686/