我想从网站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),其中包含一个源自"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.
这是Curl的结果:
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的回答所提到的,我已经在站点A的响应头中添加了Access-Control-Allow-*
,但仍然出现异常。