Chinese garbled cookies and garbled cookies

Source: Internet
Author: User

Chinese garbled cookies and garbled cookies

I encountered a Chinese garbled cookie problem during my study. cause: the cookie is not very supportive of Chinese. If I put Chinese into the cookie, an error will be reported.

Solution:

1. Encoding

Encode Chinese characters and then put them in the cookie:

String username1 = URLEncoder. encode (username, "UTF-8 ");

String userpwd1 = URLEncoder. encode (userpwd, "UTF-8 ");

Here, username and userpwd have Chinese characters, and username1 and userpwd1 are encoded strings.

2. decoding (if decoding is not performed, the page will get base64-encoded content)

String unamePwd = URLDecoder. decode (cookies [I]. getValue (), "UTF-8 ");

Here, cookies [I]. getValue () are the content to be decoded and modified according to your own situation.

 

This solves the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.