Search code examples
javaurl-encoding

Add %% in a url query parameter


I am forming a url that contains another url as one of its query string parameters. This url is supposed to return some xml code from our webapp deployed on tomcat. Below is the sample url that I am generating using Java:

http://localhost:8080/sample/url?id=1&uid=sfdgsdh&nurl=https%3A%2F%2Flocalhost%3A8080%2Fxmltag%2Freturn%3Fzid%3D1_0_1%26sid%3Dfdd61fce-29b4-11e7-9ac0-eb0a8802439b%26au_pc%3D%25%25TAG_PRICE%25%25

Now the issue is when I hit this url from browser or wget it, it returns 'ERROR 500: Internal Server Error'. But if I replace the last macro '%25%25TAG_PRICE%25%25' with some real value e.g. 5.2, then this url returns valid response.

So I assume the issue is with passing %%TAG_PRICE%% in the query string. Its not working no matter its encoded or not and I need to have this macro in my url. I tried to debug it using eclipse debugger, but its not even reaching init method of web servlet. I don't know how to fix this.

Any help is appreciated. Thanks in advance.


Solution

  • Finally I figured out that if I encode the macro %%TAG_PRICE%% twice, it works fine i.e. if I insert %2525TAG_PRICE%2525 as a query parameter in the above url, browser successfully loads its content.