HarmonyOS鸿蒙Next中视频播放时如何将Http请求中的Referer置空?
HarmonyOS鸿蒙Next中视频播放时如何将Http请求中的Referer置空? 视频播放时,需要将Http请求中的Referer置空,请问如何操作
1、DRM Kit 可实现对应的能力,实现请参考:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/drm-overview-V5
2、鸿蒙 avlpayer createMediaSourceWithUrl 接口支持传入 header,当前支持参数 User-Agent、Referer、Cookie:
更多关于HarmonyOS鸿蒙Next中视频播放时如何将Http请求中的Referer置空?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,若要在视频播放时将HTTP请求中的Referer置空,可以通过以下方式实现:
-
使用
WebView控件:如果你是通过WebView加载视频,可以通过设置WebView的WebSettings来禁用Referer。具体代码如下:const webView = new webView.WebView(); const webSettings = webView.getSettings(); webSettings.setReferer(''); // 将Referer置空 -
使用
HttpURLConnection:如果是通过HttpURLConnection发送HTTP请求,可以在请求头中手动设置Referer为空。示例代码如下:const url = new URL('http://example.com/video'); const connection = url.openConnection() as HttpURLConnection; connection.setRequestProperty('Referer', ''); // 将Referer置空 -
使用
FetchAPI:如果使用FetchAPI进行请求,可以在请求头中设置Referer为空。示例代码如下:fetch('http://example.com/video', { headers: { 'Referer': '' // 将Referer置空 } });
以上方法均可在HarmonyOS鸿蒙Next中实现将HTTP请求中的Referer置空。
在HarmonyOS鸿蒙Next中,若需在视频播放时将HTTP请求中的Referer置空,可以通过自定义网络请求头实现。使用HttpURLConnection或OkHttp时,在发起请求前设置Referer为空字符串即可。示例代码如下:
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Referer", "");
或使用OkHttp:
Request request = new Request.Builder()
.url(url)
.header("Referer", "")
.build();
确保在播放器初始化或请求配置阶段应用此设置。

