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 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.