ookie里面不能写中文,是由于cookie先天的编码方式造成的。所以需要有一种中间编码来过渡。 urlencode是最好的选择。
我们以asp.net为例,代码如下:
设置Cookie时:
HttpCookie cookie = new HttpCookie("name", System.Web.HttpContext.Current.Server.UrlEncode("雨林星空")); Response.Cookies.Add(cookie);
读取Cookie时:
if (Request.Cookies["name"] != null) { Response.Write(System.Web.HttpContext.Current.Server.UrlDecode(Request.Cookies["name"].Value)); }
注意:编码和解码要一致
System.Web.HttpContext.Current.Server.UrlDecode 和 System.Web.HttpContext.Current.Server.UrlEncode
System.Web.HttpUtility.UrlDecode 和 System.Web.HttpUtility.UrlEncode
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号