如何在 Adobe Media Server 中允许来自 Javascript 的 CORS 请求
2024-04-20
我有一个 html 页面,从 javascript 调用 HLS。收到标头“allow-control-allow-origin”的 CORS 错误。我正在使用 Adobe Media Server 4.5。
我如何允许来自 javascript 的 CORS 请求?
Adobe Media Server 使用 Apache HTTP 服务器。要启用 CORS,您需要将以下行添加到 Apache HTTP Server 配置文件:
Header set Access-Control-Allow-Origin "your_page_origin"
您需要将“your_page_origin”替换为origin https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin将发出请求的页面的名称,或使用“*”以允许来自任何域的请求。查看启用 CORS 网站 http://enable-cors.org/server_apache.html and 配置 Apache HTTP Server 文档页面 https://helpx.adobe.com/adobe-media-server/config-admin/configuring-apache-server.html了解更多信息。
另外,您还可以使用 HTMLvideo标记以嵌入 HLS。当用户代理发出请求时video它不会发送源Origin默认情况下,不会在服务器响应中搜索与 CORS 相关的标头。在这种情况下,您不需要更改服务器配置。苹果推荐使用video标签在他们的HTTP 直播概述简介 https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html:
重要的:如果可能,请使用
Check 如何使用 html5 视频标签线程播放 Apple HLS 直播 https://stackoverflow.com/questions/18434803/how-can-i-play-apple-hls-live-stream-using-html5-video-tag了解更多信息。