As we all know, when searching for Chinese Characters in "Baidu.com", for example, "Old Three" Get the URL string: http://www.baidu.com/s? WD = % C0 % CF % C8 % FD & CL = 3, which is clearly encoded. What's going on?
Because some symbols cannot be directly transmitted in the URL, if you want to pass these special symbols in the URL, you need to use their encoding. The encoding format is % plus the characters' ASCII code, that is, a percent sign %, followed by the corresponding characters' ASCII (hexadecimal) code value. For example, the Space Encoding value is "% 20 ".
The following table lists some special URL symbols and codes.
|
|
|
Hexadecimal value |
1. |
+ |
The plus sign in the URL indicates space. |
% 2B |
2. |
Space |
Spaces in the URL can be encoded with a plus sign (+ ). |
% 20 |
3. |
/ |
Separate directories and subdirectories |
% 2f |
4. |
? |
Separate actual URLs and Parameters |
% 3f |
5. |
% |
Special characters |
% 25 |
6. |
# |
Indicates bookmarks |
% 23 |
7. |
& |
Delimiter between parameters specified in the URL |
% 26 |
8. |
= |
The value of the specified parameter in the URL. |
% 3d |
So how do we encode and decode it? See the following code:
// Add system. Web reference first.
/// <Summary>
/// URL Decoding
/// </Summary>
/// <Param name = "Source"> uncode string </param>
/// <Param name = "encode"> encoding format of the string to be decoded </param>
/// <Returns> decoded string </returns>
Public static string urldecode (string source, encoding encode)
{
Return System. Web. httputility. urldecode (source, encode );
}
/// <Summary>
/// URL Encryption
/// </Summary>
/// <Param name = "Source"> string to be encrypted </param>
/// <Param name = "encode"> encoding format of the string to be encrypted </param>
/// <Returns> encrypted string </returns>
Public static string urlencode (string source, encoding encode)
{
Return System. Web. httputility. urlencode (source, encode );
}
Result of the old Three encoding conversion tool: