0

我试图弄清楚如何让网络种子播放视频,但我遇到了一些奇怪的错误。这是一个粘贴箱: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)
4

1 回答 1

0

解释在错误消息中,但简而言之:您的浏览器阻止了请求,因为您使用 AJAX 与远程服务器通信,并且该服务器没有发送适当的“Access-Control-Allow-Origin”标头。

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

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

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

于 2019-06-21T12:56:30.767 回答