yeah its me
yeah its me

Reputation: 1141

Java how to escape "&" character in url params?

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?

Upvotes: 0

Views: 158

Answers (2)

Masudul
Masudul

Reputation: 21961

Encode your password using URLEcoder#encode with utf-8

String urlParameters = "login=test&password="+
                  URLEncoder.encode("te&ff", "UTF-8");

Upvotes: 1

JP Moresmau
JP Moresmau

Reputation: 7403

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

Upvotes: 1

Related Questions