Why do I need to encode the URL

Source: Internet
Author: User
Tags control characters form post urlencode alphanumeric characters

Posted on 2016-03-12 07:30 found that almost all websites now have urlencode operations on Chinese characters and special characters in URLs, namely: http://hi.baidu.com/%BE%B2%D0%C4%C0%CF%C8%CB/ creat/blog/this way, in the middle of the form, it is definitely my login user name. Why do you encode these characters in the form of a character encoding (GBK, UTF8) or in order to not have special characters in the URL? All know to turn, but the real benefit of the turn. Viewed a lot of information on the Internet, and did not find a more accurate statement. URL escaping is only intended to conform to URL specifications. Because Chinese and many characters in the standard URL specification are not allowed to appear in the URL. Take a look at Php's UrlEncode description: The urlencode-encoded URL string UrlEncode (String $str) returns a string in addition to-_. All non-alphanumeric characters are replaced with a percent sign (%) followed by a two-digit hexadecimal number, and a space is encoded as a plus (+). This encoding is the same as the WWW form POST data, and is encoded in the same way as the application/x-www-form-urlencoded media type. For historical reasons, this encoding differs from RFC1738 encoding (see Rawurlencode ()) in terms of encoding spaces as plus signs (+). This function makes it easy to encode a string and use it for the request part of the URL, and it also facilitates the passing of a variable to the next page. What characters are needed for conversion? 1. ASCII control characters These characters are non-printable and naturally require conversion. 2. Some non-ASCII characters these characters are naturally illegal character ranges. Transformation is also a matter of course. 3. Some reserved characters are obviously the most common is "&", if it appears in the URL, then you think it is a character in the URL, or special parameter segmentation? 4. It's just some unsafe characters. For example: spaces. To prevent ambiguity, you need to be converted to "+". Knowing this, you know why you need to convert, and the rules of transformation are simple. According to the character encoding of each character, not in line with our range, all the conversion to% of the form is also. Nature is also 16 in the form of the binary. and character encoding regardless of the conversion rules and purposes of urlencode, it is also easy to see that Urleocode is based on character encoding. The same kanji, different encoding types, certainly correspond to the strings of different urleocode. GBK encoded with GBK Enco.De results. Apache and other servers, after accepting the string, can be decode, but still cannot solve the problem of encoding. Coding problems, or the need to rely on conventions or character coding to solve the judgment. Therefore, Urleocode is only for some non-ASCII characters in the URL, it can be transmitted correctly, as to which encoding to use, it is not encode concern and solve the problem. Coding problem, not urlencode to solve.

Why do I need to encode a URL

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.