前端關鍵代碼:
如圖,在請求上加個 withCredentials: true 即可。
當然,這只是前端打開一個開口而已,后端做的事情可就多了。
如圖,后端服務在進行跨域處理的時候,需要將 Access-Control-Allow-Credentials 設為 true 即可。
原理:
以上前后端設置的ture屬性(withCredentials、Access-Control-Allow-Credentials),都是允許跨域發送cookie的一個開關設置,需要前后端都做到打開模式。
參考資料:
關於請求跨域及response中Set-Cookie無效問題記錄