网络洪流坏了



我试图弄清楚如何让网络洪流播放视频,但我遇到了一些奇怪的错误。这是一个糊状物: https://pastebin.com/raw/3wp5F8Fh

这是一个实时版本:https://41182065-e8d9-40b1-8dd9-9433b402bce9.htmlpasta.com/

当我们转到chrome控制台时,我们得到这个:

Mixed Content: The page at 'https://41182065-e8d9-40b1-8dd9-9433b402bce9.htmlpasta.com/' was loaded over HTTPS, but requested an insecure script 'http://momentjs.com/downloads/moment.min.js'. This request has been blocked; the content must be served over HTTPS.
/favicon.ico:1 Failed to load resource: the server responded with a status of 404 ()
(index):1 Access to XMLHttpRequest at 'https://nyaa.si/download/941788.torrent' from origin 'https://41182065-e8d9-40b1-8dd9-9433b402bce9.htmlpasta.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
webtorrent.min.js:4 Uncaught Error: Error downloading torrent: XHR error
at webtorrent.min.js:5
at t.exports.<anonymous> (webtorrent.min.js:7)
at t.exports.t (webtorrent.min.js:5)
at t.exports.r.emit (webtorrent.min.js:4)
at XMLHttpRequest.c.onerror (webtorrent.min.js:7)

解释在错误消息中,但简而言之:您的浏览器阻止了请求,因为您正在使用 AJAX 与远程服务器通信,并且该服务器未发送适当的"访问控制-允许源"标头。

阻止此类请求的原因是为了保护您免受恶意脚本的侵害 - 如果您登录到网站 A 并有权访问某些私有数据,则网站 B 应该无法触发 AJAX 请求来访问该数据,除非 A 信任 B。

这种访问的一般术语是"跨源资源共享"或"CORS" - 有关更多信息,Mozilla 在这里有一个很好的总结:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

如果您控制了远程服务器,则使用适当的标头进行响应将允许请求通过(但请注意,某些浏览器(如 Safari)仍会阻止来自远程服务器的 cookie,因为此技术可用于跟踪)。

最新更新