12

I have a the following url:

http://www.test.com/?client=xyz&redirect_uri=http://www.xyz.com/x?p1=one&p2=two

How should I url encode these so that the browser does not interpret p1 and p2 as query strings of the test.com when they are actually part of the redirect_uri parameter.

3

1 Answer 1

13

I quote this question that uses JavaScript. And this answer by Dustin Boswell.

encodeURIComponent() should work. For example,

'&url=' + encodeURIComponent("http://a.com/?q=query&n=10")

produces

"&url=http%3A%2F%2Fa.com%2F%3Fq%3Dquery%26n%3D10"

(which doesn't have any '&' or '?' in the value). When your server gets this url, it should be able to decode that to get the original:

param["url"] = "http://a.com/?q=query&n=10"

I'm not sure what server you're using (e.g. Rails, Django, ...) but that should work "out of the box" on any normal system.

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.