我有一个 html 页面,从 javascript 调用 HLS。收到 header “allow-control-allow-origin”的 CORS 错误。我正在使用 Adobe Media Server 4.5。 我如何允许来自 javascript 的 CORS 请求?
最佳答案
Adobe Media Server 使用 Apache HTTP Server。要启用 CORS,您需要将以下行添加到 Apache HTTP Server 配置文件:
Header set Access-Control-Allow-Origin "your_page_origin"
您需要将“your_page_origin”替换为 origin将发出请求的页面的名称,或使用“*”以允许来自任何域的请求。检查Enable CORS web site和 Configuring Apache HTTP Server documentation page了解更多信息。
此外,您还可以使用 HTML video
标签来嵌入 HLS。当用户代理向 video
源发出请求时,默认情况下不会发送 Origin
header ,并且不会在服务器响应中搜索与 CORS 相关的 header 。在这种情况下,您不需要更改服务器配置。 Apple 建议在其 introduction to HTTP Live Streaming Overview 中使用 video
标签:
Important: Where possible, use the <video> tag to embed HTTP Live Streaming, and use the <object> or <embed> tags only to specify fallback content.
检查How can I play Apple HLS live stream using html5 video tag thread了解更多信息。
关于javascript - 如何在 Adobe Media Server 中允许来自 Javascript 的 CORS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41158655/