System. Web. httputility. urlencode: encode and convert Chinese characters and URLs

Source: Internet
Author: User

Today, I am working on a small program to find that the encoding produced by the C # system. Web. httputility. urlencode function is different from that we normally use, for example:

The encoding produced by using system. Web. httputility. urlencode is as follows:

Nanjing: % E5 % 8d % 97% E4 % Ba % AC

The expected result is % c4 % CF % be % A9.

After comparison, it is found that the two are considered to be one Chinese character with three bytes, while the latter is two bytes. This suddenly realizes that if system is used directly in C. web. httputility. urlencode ("Nanjing") then the program uses UTF-8 encoding to process Chinese characters by default.

 

Solution:

System. Web. httputility. urlencode ("Nanjing", encoding. getencoding ("gb2312 "))

Add a parameter!

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.