响应标头中的Access-Control-Allow-Origin是否区分大小写?

OhM*_*osh 4 javascript html5 httpresponse httprequest http-headers

我想从站点B访问站点A的内容。因此,我将站点B的Access-Control-Allow-Origin配置为通配符(*)。但是,配置后,我将获得跨域异常。然后,我尝试卷曲站点A url,并得到以下结果:

access-control-allow-headers: *
access-control-allow-origin: *
Run Code Online (Sandbox Code Playgroud)

因此,我不确定是因为关键字Access-Control-Allow-Origin是否区分大小写吗?

我试图四处搜寻,找不到任何文档指定必须是驼峰式大小写。

更新:

让我解释一下我到底发生了什么:

  1. 我有网站B(https://siteB.com),其中的iframe带有src =“ https://siteA.com ”。

  2. 在网站B上,我有一个脚本来获取该iframe的动态高度:

    function showPageDialog(url, id, title, onCloseDialog) { var iframe = $('<iframe/>', {'class': 'frame', 'src': url}).load(function(){ setTimeout(function() { $(iframe).height($(iframe).contents().height()); }, 100); }); showDialog(iframe, id, title, onCloseDialog); }

该函数在访问$(iframe).contents()时发生异常,异常详细信息如下:

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://siteB.com" from accessing a cross-origin frame.
Run Code Online (Sandbox Code Playgroud)

这是卷曲结果:

HTTP/1.1 200 OK
Server: Apache
ETag: "f8daec99fedb6b0cd0d205598167cf11:1477550373"
Last-Modified: Thu, 27 Oct 2016 06:39:33 GMT
Accept-Ranges: bytes
Content-Length: 44152
Content-Type: text/html
Date: Mon, 31 Oct 2016 09:14:19 GMT
Connection: keep-alive
access-control-allow-headers: *
access-control-allow-origin: *
Run Code Online (Sandbox Code Playgroud)

就像@duskwuff的答案中提到的那样,我在siteA的Access-Control-Allow-*响应标头中也有。但仍然得到例外。

dus*_*uff 5

不,标头不区分大小写。

您的问题更简单:Access-Control-Allow-*标头仅影响标头出现的站点。站点B发送的标头只能通过脚本授予对站点B的访问权限;它不能授予对单独站点A的访问权限。

如果要从在站点B上运行的脚本访问站点A,则需要让站点A添加Access-Control-Allow-*标头,或者找到另一种不涉及从脚本访问它的解决方案。