【发布时间】:2017-03-13 04:24:29
【问题描述】:
我想从站点 B 访问站点 A 的内容。因此,我将站点 B 的 Access-Control-Allow-Origin 配置为通配符 (*)。但是,配置后我会得到跨域异常。然后,我尝试 curl 站点 A url,并得到以下结果:
access-control-allow-headers: *
access-control-allow-origin: *
所以,我不确定是不是因为关键字 Access-Control-Allow-Origin 区分大小写?
我试图四处搜索,找不到任何说明它必须是驼峰式的文档。
更新:
让我解释一下发生在我身上的真实情况:
我有一个站点 B (https://siteB.com),它有一个带有 src="https://siteA.com" 的 iframe。
-
在站点 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.
这是卷曲结果:
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: *
正如@duskwuff 的回答中提到的,我在siteA 的响应标头中有Access-Control-Allow-*。但仍然得到异常。
【问题讨论】:
-
感谢您的快速回复,我想念那个帖子! :p
标签: javascript html http-headers httprequest httpresponse