• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

special character for space in URL

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing improper about using + to encode spaces in URLs.
 
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


reply
    Bookmark Topic Watch Topic
  • New Topic