tags:

views:

47

answers:

3

Why do you need to encode urls? Is there a good reason why you have to change every space in the GET data to %20?

+4  A: 

From RFC 2936, section 2.4.3:

The space character is excluded because significant spaces may disappear and insignificant spaces may be introduced when URI are transcribed or typeset or subjected to the treatment of word- processing programs. Whitespace is also used to delimit URI in many contexts.

Ignacio Vazquez-Abrams
cant get more precise than the RFC
Perpetualcoder
In other words, "No, there's not an inherent technical reason but we know implementors and users are both sloppy." It was probably the correct decision, mainly because users would have trouble keeping the right amount of space.
Matthew Flaschen
@Matthew - There is a inherent technical reason, see my answer
Rippo
@Rippo: Your answer claims that they are "unsafe", but does not give any technical reason why.
Ignacio Vazquez-Abrams
@Matthew - In my experience unsafe means that there must be a technical reason...
Rippo
A: 

Since URLs often contains characters outside the ASCII set, the URL has to be converted. URL encoding converts the URL into a valid ASCII format.

Therefore URL encoding converts characters into a format that can be safely transmitted over the Internet.

URLs can only be sent over the Internet using the ASCII character-set.

URL encoding replaces unsafe ASCII characters with "%" followed by two hexadecimal digits corresponding to the character values in the ISO-8859-1 character-set. URLs cannot contain spaces. URL encoding normally replaces a space with a + sign

Rippo
A: 

Well, you do so because every different browsers knows how the string that makes up the URL is encoded. converting the space to %20, etc makes that URL/URI portable. It could be latin-1 it could be unicode. It needs normalized to something that is understood universally. Take a look at rfc3986 http://tools.ietf.org/html/rfc3986#section-2.1

brianray