0
String urlParameters = "login=test&password=te&ff";

I have a String urlParams, & - is part of the password, how to make it escaped, thus not be recognized as a separator?

yeah its me
  • 1,131
  • 4
  • 18
  • 27
  • 2
    possible duplicate of [escaping ampersand in url](http://stackoverflow.com/questions/16622504/escaping-ampersand-in-url) – Wim Ombelets Apr 11 '15 at 15:15
  • why is this being upvoted when it displays a blatant lack of research? – Wim Ombelets Apr 11 '15 at 15:16
  • @WimOmbelets He either has friends, or there's a bunch of new people currently online. Either way, it happens all the time. Simply vote to close as a duplicate – Vince Apr 11 '15 at 15:38

2 Answers2

1

Use a URL Encoder on each of the components: http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html

JP Moresmau
  • 7,388
  • 17
  • 31
  • but again will he recognize the & symbol?, that is not a separator? – yeah its me Apr 11 '15 at 15:11
  • You encode each component separately: you encode the login, the password, then build the url. See also http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters for alternatives – JP Moresmau Apr 11 '15 at 15:16
1

Encode your password using URLEcoder#encode with utf-8

String urlParameters = "login=test&password="+
                  URLEncoder.encode("te&ff", "UTF-8");
Masudul
  • 21,823
  • 5
  • 43
  • 58