I came across a simple but interesting solution when working on a project that required sending query string that contains another query string (i.e. a URL Inception :) ... )
First Pass:
http://somedomain.com/someservice?query=http://anotherdomain.com/anotherservice?dream1=value1
Which works fine as long as you are sending a single query string.
However, if you have additional query string your data breaks at the first ampersand of the second query string.
i.e. http://somedomain.com/someservice?dream1=value1&dream2=http://anotherdomain.com/anotherservice?&subdream1=subdreamvalue1
will be interpreted as:
after the URL is translated in a browser.
The Solution:
Using good old URL encoding. Changing the ampersand in the second query string to %26
fixes the issue.
i.e.
http://somedomain.com/someservice?dream1=value1&dream2=http://anotherdomain.com/anotherservice?%26subdream1=subdreamvalue1
Will have all query strings in their respective URL.
First Pass:
http://somedomain.com/someservice?query=http://anotherdomain.com/anotherservice?dream1=value1
Which works fine as long as you are sending a single query string.
However, if you have additional query string your data breaks at the first ampersand of the second query string.
i.e. http://somedomain.com/someservice?dream1=value1&dream2=http://anotherdomain.com/anotherservice?&subdream1=subdreamvalue1
will be interpreted as:
after the URL is translated in a browser.
The Solution:
Using good old URL encoding. Changing the ampersand in the second query string to %26
fixes the issue.
i.e.
http://somedomain.com/someservice?dream1=value1&dream2=http://anotherdomain.com/anotherservice?%26subdream1=subdreamvalue1
Will have all query strings in their respective URL.
Comments