我们以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