views:

410

answers:

1

I have a url like this: product//excerpts?feature=picture+modes

when i access this url from browser, the backend receives the request as: "product//excerpts?feature=picture+modes"

At the web server end, i am using + as a separator. so feature=picture+modes means there are 2 features: picture and modes

I have created and automated script(Java) which goes to the url and retrieves its content. When i run this script, the backend receives the request as: "product/B000NK6J6Q/excerpts/feature=picture%2Bmodes"

This is because inside my script(Java) i use URLEncoder.encode which converts + to %2B and send this encoded url to the server.

Why are the urlEncoders provided by Java and those present with browsers(FF/IE) different. how do i make them same? How do i decode them? ('+' on URLDecoder.decode gives space) Also, is using '+' as a separator according to conventions (and specifications?) ?

Prac

+1  A: 

What you are seeing is actually correct. See Percent encoding on Wikipedia. The + character is a reserved character and therefore needs to be encoded as %2B. Furthermore, historically browsers use a different form of percent encoding for forms that are submitted with the MIME type application/x-www-form-urlencoded where spaces become + instead of %20.

If you want to use a + in the URL then your separator should be a space in the backend. If you want to use + in the backend, then you will have %2B in the URL.

Joey