iphone不能在cookie中写入中文字符的解决办法

时间:2021-07-23 07:42:34

情景:

后台想通过cookie向客户端写入数据,安卓手机可以,但是ios就是不行,后来排查发现ios不能写入中文字符

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码的汉字,是不被认可的字符。那么只好对汉字进行了UrlEncode,读取的时候再来UrlDecode。