Java URL encoding -


from web application doing redirect external url has credentials part of url string. encode credential part alone before redirection. have following url:

string url1 = "http://servername:7778/reports/rwservlet?server=server1&oracle_shutdown=yes&paramform=no&report=test.rdf&desformat=pdf&desname=test.pdf&destype=cache&param1=56738&faces-redirect=true&"; 

i encoding as:

string url = "userid=username/passwd@dbname"; encodedurl = urlencoder.encode(url, "utf-8"); string redirecturl = url1 + encodedurl1; 

the url generated code is

http://servername:7778/reports/rwservlet?server=server1&oracle_shutdown=yes&paramform=no&report=test.rdf&desformat=pdf&desname=test.pdf&destype=cache&param1=56738&faces-redirect=true&userid=%3dusername%2fpasswd%40dbname 

as can see towards end of encoded url, special characters / have been encoded. i.e. userid=username/passwd@dbname has become userid=%3dusername%2fpasswd%40dbname

i want generate url have the entire string "username/passwd@dbname" encoded . :

userid=%61%62 

how can achieve this?

so in fact want url become unreadable, without need decoding, decoding needed base64 encoding (with replacing / , -).

yes may abuse url encoding.

string encodeurl(string s) {     byte[] bytes = s.getbytes("utf-8");     stringbuilder sb = new stringbuilder();     (byte b : bytes) {         string hex = string.format("%%%02x", ((int)b) & 0xff);         sb.append(hex);     }     return sb.tostring(); } 

%% being percentage sign itself, , %02x hex, 2 digits, zero-filled, capitals.

mind browsers display such links decoded, on mouse-over. redirecting.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -