簡體   English   中英

如何在請求加密密鑰時使hls.js在請求標頭中發送cookie

[英]How can I make hls.js send the cookie in request header upon requesting encryption key

我試過了

var config = {
       xhrSetup: function (xhr) {
          xhr.withCredentials = true; // do send cookies
       }
    };

但這不起作用。 無論我是否在xhrSetup中啟用憑據而不是在密鑰請求上啟用憑據,都會根據播放列表請求和段請求發送Cookie。 為了保護內容,我需要在分發密鑰之前識別用戶。 我可以在答案中設置“X-Cookie”,但是如何發送會話cookie?

我像這樣設置了一個“X-Cookie”:

    var config = {
        debug: true,
        xhrSetup: function (xhr,url) {
            xhr.withCredentials = true; // do send cookie
            xhr.setRequestHeader("X-Cookie", read_cookie('SESSIONID'));
        }
    };

在另一方面它需要

Header set Access-Control-Allow-Headers "X-Cookie"

read_cookie函數:

function read_cookie(key) {
   var result;
   (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? (result[1]) : null;
   console.log('result : ' + result[1]);
   return result[1]
}

有沒有辦法發送Cookie值?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM