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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With