Difference between revisions of "URL Encoding"

From LongJump Support Wiki
imported>Aeric
imported>Aeric
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Note|<br>When specifying a URL in code, any ''special characters'' (characters other than letters and numbers) need to be ''encoded''. For example, a space character is encoded as <tt>%20</tt>.
{{Note|<br>When specifying a URL in code, any ''special characters'' (characters other than letters and numbers) need to be ''encoded''. For example, a space character is encoded as <tt>%20</tt>.


(Browsers typically take care of encoding URLs entered into the address bar--so the URL displayed after you visit a page may differ somewhat from the one you entered.)
(Browsers typically take care of encoding URLs entered into the address bar--so the URL displayed after visiting a page may differ somewhat from the one that was initially entered.)


Here are some typical encodings:
{{:Common:URL Encoding Characters}}
It can be hard to get be hard to get the encoding right, so it's desirable to use a language library designed for the purpose.<br>
''Learn more:''  
''Learn more:''  
:* [http://www.w3schools.com/tags/ref_urlencode.asp URL Encoding] in HTML
:* [http://www.w3schools.com/tags/ref_urlencode.asp URL Encoding] in HTML
:* [http://www.javascripter.net/faq/escape.htm Encode a URL] in JavaScript
:* [http://www.javascripter.net/faq/escape.htm Encode a URL] in JavaScript
:* [http://docs.oracle.com/javase/6/docs/api/java/net/URLEncoder.html URLEncoder] class for Java}}
:* [http://docs.oracle.com/javase/6/docs/api/java/net/URLEncoder.html URLEncoder] class for Java}}

Latest revision as of 20:31, 29 March 2013

Notepad.png

Note:
When specifying a URL in code, any special characters (characters other than letters and numbers) need to be encoded. For example, a space character is encoded as %20.

(Browsers typically take care of encoding URLs entered into the address bar--so the URL displayed after visiting a page may differ somewhat from the one that was initially entered.)

Here are some typical encodings:

space
+
%
%20
%2B
%25

So:

Instead of Use

& (A&B)
space (A B)

%26 (A%26B)
%20 (A%20B)


It can be hard to get be hard to get the encoding right, so it's desirable to use a language library designed for the purpose.
Learn more: