IOS safari瀏覽器登陸時Cookie無法儲存的問題

李文楊發表於2017-10-13

近期完成了一個兒童的測評專案,測試到最後的時候發現在ipad mini上登陸成功之後無法跳轉頁面,而安卓和pc端都可以,找了大半天bug,發現其他的蘋果裝置都沒問題,只能一個一個的除錯,結果發現裝置的系統是ios8.3,在該系統下cookie沒有設定上,導致沒有跳轉。

找了好多的資料,國內的,基本都是牛頭不對馬嘴,根本不是這回事。

最後直接google國外的資料,終於在第n頁看到了一個帖子:http://stackoverflow.com/questions/5327341/strange-problem-with-cookies-in-safari-and-asp-net。

找到問題所在了:Safari will not set cookies with non-ASCII characters in their value and other browsers can be unpredictable in how they display non-ASCII characters. As semi-colon is also not allowed in cookie values for any browser I would recommend using UrlEncode/UrlDecode.

就是非ASCII碼的漢字或符號,是不被認可的字元。那麼只好對需要設定的cookie進行了UrlEncode,讀取的時候再來UrlDecode。

測試結果:OK!

相關文章