1
function sendToken():void{
console.log("In sendToken();")
var cookie_name="auth_token_seven";
var xhr;
var hash;
if(!docCookies.getItem(cookie_name)){
console.log("Token not found!");
hash="8617f366566a011837f4fb4ba5bedea2b892f3ed8b894023d16ae344b2be5881";
this.docCookies.setItem(cookie_name,hash,"/",4000, true);
console.log("Token set");
xhr= new XMLHttpRequest();
xhr.open("POST","myurl", true);
xhr.withCredentials=true;
xhr.setRequestHeader("Cookie",cookie_name=hash);
xhr.send();
}
else{
console.log("Token found");
hash=docCookies.getItem(cookie_name);
console.log("getting Token");
xhr= new XMLHttpRequest();
xhr.open("POST", "myurl", true);
xhr.withCredentials=true;
xhr.setRequestHeader("Cookie", cookie_name=hash);
xhr.send();
}
嗨,我使用cookie.js來設置一個cookie,當用戶登錄我的網站。 我想要做的是在用戶登錄我的網站時,在cookie中設置一個auth令牌,每當用戶嘗試訪問我網站上的某些功能時,這個帶有auth令牌的cookie就會發送到服務器。拒絕設置不安全標題「Cookie」
我面對的問題是,Chrome不允許通過顯示警告消息來設置Cookie 拒絕設置不安全標題「Cookie」。
我看了一個鏈接Refused to set unsafe header "Cookie" error in browser yet request is successful。 我試過我的方式,但它仍然無法正常工作。
任何人都可以請建議一個解決方案。