简体   繁体   English

CORS要求在Chrome中无法使用

[英]CORS request will not work in Chrome

I know this question has been asked before, I have read/tried them all. 我知道之前曾有人问过这个问题,我已全部阅读/尝试过。 I am needing to do createMediaElementSource on mp3 files stored on a different domain for visualizations. 我需要对存储在不同域中的mp3文件执行createMediaElementSource以便可视化。 What I have works well in Safari and Edge but not in Chrome (dunno about FireFox). 我所拥有的功能在Safari和Edge中运行良好,但在Chrome中却无法运行(对FireFox不满意)。 The issue is if I create the element from a cross-origin source using: 问题是,如果我使用以下方法从跨域源创建元素:

var audioSrc = ctx.createMediaElementSource(cfg.audio);

...where cfg.audio is cross-domain, Chrome gives me: ...如果cfg.audio是跨域的,Chrome给了我:

MediaElementAudioSource outputs zeroes due to CORS access restrictions

But I have (among other things) in my .htaccess: 但是我的.htaccess中有(除其他外):

Header set Access-Control-Allow-Origin: "http://the-correct-domain.com"

I have checked the header at the webconfs.com site and am getting: 我已经在webconfs.com网站上检查了标头,并得到:

HTTP/1.1 200 OK => 
Date => Fri, 09 Dec 2016 20:52:17 GMT
Server => Apache
Last-Modified => Thu, 27 Jun 2013 20:55:40 GMT
ETag => "2d60fc-4e028fc23173e"
Accept-Ranges => bytes
Content-Length => 2973948
Access-Control-Allow-Origin => http://the-correct-domain.com
Access-Control-Allow-Credentials => false
Access-Control-Allow-Methods => ACL, CANCELUPLOAD, CHECKIN, CHECKOUT, COPY, DELETE, GET, HEAD, LOCK, MKCALENDAR, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PROPPATCH, PUT, REPORT, SEARCH, UNCHECKOUT, UNLOCK, UPDATE, VERSION-CONTROL
Access-Control-Allow-Headers => Overwrite, Destination, Content-Type, Depth, User-Agent, Translate, Range, Content-Range, Timeout, X-File-Size, X-Requested-With, If-modified-Since, X-File-Name, Cache-Control, location, Lock-Token
Connection => close
Content-Type => audio/mpeg

(I started with a simple Access-Control-Allow-Origin: "*" and have added crap from that point). (我从一个简单的Access-Control-Allow-Origin:“ *”开始,并从那时开始添加了废话)。 The script works just fine using a local mp3 file, and I tried adding PHP voodoo from HERE to no avail. 使用本地mp3文件可以正常运行脚本,我尝试从此处添加PHP voodoo毫无用处。 Where have I gone wrong? 我哪里出问题了?

Got it at long last, thanks to this post . 多亏了这篇文章 ,终于找到了它。 I changed the script from audio.crossOrigin = 'Anonymous' to audio.crossOrigin = 'use-credentials' and all is well. 我将脚本从audio.crossOrigin = 'Anonymous'更改为audio.crossOrigin = 'use-credentials' ,一切都很好。 You're my hero pdg137 ! 你是我的英雄pdg137

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

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