Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

special character for space in URL

 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know we can use %20 to replace any space character. For example,

http://myserver/myaction?param1=abc%20def¶m2=xyz

But when I use URLEncoder.encode API to encode the parameter values I find it converts space character into "+" instead of %20. When I use "+" to replace the %20 in URL it also works.

So is it true that both "+" and "%20" can be used to replace space char in URL ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The MIME type of the data being encoded plays a role. It may even be browser dependent - application/x-www-form-urlencoded uses + and properly encoded URIs use %20.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing improper about using + to encode spaces in URLs.
 
Howard Watson
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never seen + used in place of %20 in a URL. Decided that since I spent a few minutes thinking on this one to share the references.

RFC 2396: http://www.ietf.org/rfc/rfc2396.txt, sections 2.2 and 3.4.

I visualize URI = URL + URN. I think of the query string as a kind of extension to the URI and not part of my HTTP request, the URN located at URL.

A Google of this topic got several hits to the effect that %20 is interchangeable with + in a URL. They all have a similar example URL.

I finally found this: http://www.w3.org/Addressing/URL/4_URI_Recommentations.html, the section Query strings.

This method was used to make query URIs easier to pass in systems which did not allow spaces.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic