[Reprint] garbled characters are displayed in URLs with Chinese Parameters

Source: Internet
Author: User

Address: http://www.cnblogs.com/inday/archive/2008/01/12/1035902.html

If you want to bind an image to a repeater, use the HTML image button,

'/>

..

Because this public conversion file is for all substations, there are two types of substation code:. NET and ASP, and the file encoding format is different.

The first big thing started. The file code of the ASP site is gb2312, though. net file format is also gb2312, but because the requestencoding set in webconfig is utf8, no matter how you decode urldecode when receiving Chinese characters, even if you specify to use gb2312 for decoding, garbled characters are returned. At this time, you will change the webconfig file! If it is your own small project, such changes may be nothing, but if it involves many projects, what should you do if you cannot change it ????

Let's take a look at the example:
Environment:
ASP: File Name: Test. asp file encoding: gb2312
. Net: File Name: Test. aspx, test. aspx. CS file encoding: gb2312
. Net: File Name: Go. aspx, go. aspx. CS file encoding: gb2312
Test. ASP code:

<%
STR = server. urlencode ("Chinese test ")
Response. Redirect "Go. aspx? Name = "& Str
%>

Test. aspx. CS code:

String STR = httputility. urlencode ("Chinese test ");
Response. Redirect ("Go. aspx? Name = "+ Str );

Go. aspx. CS code:

String name = httputility. urldecode (request ["name"], encoding. getencoding ("gb2312 "));

Response. Redirect ("http://www.xxx.com? Name =
"+ Httputility. urlencode (name ));

Actually in go. aspx. in CS, we thought the encoding was set to gb2312, and it should be normal. In fact, it was wrong. I tracked it and decoded it during request ["name, it is decoded according to webconfig, that is, utf8.

OK ,.. net, you can specify the encoding for URL encoding, test. aspx. CS can be changed to: httputility. urlencode ("Chinese test", encoding. getencoding ("UTF-8") such as go. aspx is fully converted after receiving the message.

The server. urlencode of ASP does not have this parameter. What should I do?
Two methods:
1. Save test. ASP as UTF-8 encoding.
2. I just thought of a solution.
As mentioned above, I cannot change the encoding of all the projects involved. If the modification is too large for the website, I can only find another solution.

After a lot of tests, I found that urlencode was transcoded into the % AB % CD format. We all know that urlencode will be returned to you intact during English transcoding. For example, if you upload, the receiver also receives a, % will be converted to % 25, and % 25 will be decoded at urldecode decoding regardless of your encoding to %

Okay, I have a good idea. Suppose the "Chinese test" code is % AB % Cd % EF % GH.

STR = server. urlencode ("Chinese test") '% AB % Cd % EF % GH
Str1 = server. urlencode (server. urlencode ("Chinese test") '% 25ab % 25cd % 25ef % 25gh

Let's change go. aspx. CS.

Response. Write (httputility. urldecode (request ["str"], encoding. getencoding ("gb2312 "));

Response. Write (httputility. urldecode (request ["str1"], encoding. getencoding ("gb2312 "));

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.