The cookie cannot contain Chinese characters because of its inherent encoding method. Therefore, an intermediate encoding is required for transition. URLEncode is the best choice.
Take asp.net as an example. The Code is as follows:
When setting cookies:
Copy codeThe Code is as follows:
HttpCookie cookie = new HttpCookie ("name", System. Web. HttpContext. Current. Server. UrlEncode (" "));
Response. Cookies. Add (cookie); when reading Cookies:
If (Request. Cookies ["name"]! = Null)
{
Response. Write (System. Web. HttpContext. Current. Server. UrlDecode (Request. Cookies ["name"]. Value ));
}
Note:: Encoding and decoding must be consistent.
Copy codeThe Code is as follows:
System. Web. HttpContext. Current. Server. UrlDecode and System. Web. HttpContext. Current. Server. UrlEncode
System. Web. HttpUtility. UrlDecode and System. Web. HttpUtility. UrlEncode