Confusing URL encoding

Source: Internet
Author: User

reprinted from: http://www.ruanyifeng.com/blog/2010/02/url_encoding.html

One. The origin of the problem. URL is the URL, as long as the Internet is bound to use. In general, URLs can use only English letters, Arabic numerals, and certain punctuation marks, and cannot use other text or symbols. For example, the world has the English alphabet URL, http://www.xyz.com ' But there is no Greek URL for http://aerfa,beita,segma.com. This is because the networkStandard RFC 1738 makes the hard rules: only letters and numbers [0-9a-za-z], some special symbols $-_.+!*'(), and some reserved words, can be used without encoding directly for URLsThis means that if there is a Chinese character in the URL, it must be encoded and used. But the trouble is that rfc_1738 does not prescribe specific coding methods, but instead gives it to the application ' browser ' to decide. This causes URL encoding to become a chaotic area. Let's see how confusing the URL code is. I'll analyze four different situations in turn, and in each case, the browser's encoding method is not the same. After explaining their differences, I'll say how to use JavaScript to find a unified coding method. 1, http://zh.wikipedia.org/wiki/Spring FestivalConclusion 1: The code of the URL is UTF8 encoded .2, http://www.baidu.com/s?wd= Spring FestivalConclusion 2: The query string is encoded using the default encoding of the operating system. 3, in the browser directly enter the Spring festival Baidu Google conclusion 3:get and post method encoding, with the page encoding4, the URL of the AJAX call contains the kanji Ex:url=url+"? q="+ document.form.getelements[0].value.//Suppose the expression is submitted for the Spring Festival. Http_request.open ('GET'Urltrue); Conclusion 4: In Ajax calls, IE always uses GB2312 encoding (i.e. the operating system default encoding), and Firefox always uses UTF-8 encoding.

Confusing URL encoding

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.