Why url encode, or which characters to encode

后端 未结 4 942
独厮守ぢ
独厮守ぢ 2021-01-04 08:46

http://www.w3schools.com/tags/ref_urlencode.asp

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid

4条回答
  •  醉话见心
    2021-01-04 09:16

    As noted, spaces are not valid in URLs. Most browsers orlencode them automatically. However...

    The page you linked to has an example using the word "Günter" in the "Try me" section. If the word "Günter" were sent as a querystring parameter, it wouldn't work. as the "ü" is not in the standard ASCII character set.

    It's meant to be used when there are potentially non-ASCII characters. An example might be when using data from a database to create a hyperlink. Suppose the code creates a link to a user profile page. Unencoded, mine would be:

    Your profile
    

    while Günter's would be

    Your profile
    

    Mine, most browsers could handle. Günter's, probably not.

    Encoded, these would become

    Your profile
    

    and

    Your profile
    

    which are valid URLs.

    (Please forgive the fact that most well-designed systems wouldn't pass a username in a parameter like that. This was just a sample to clarify the concept.)

提交回复
热议问题