I need to send encoded username and Password through request body. Here I'm sending username and password in the format of JSON object.
How to do it?
Thanks in advance.
I need to send encoded username and Password through request body. Here I'm sending username and password in the format of JSON object.
How to do it?
Thanks in advance.
Try
Encode
String encodedUsername = URLEncoder.encode(username);
String encodedPassword = URLEncoder.encode(password);
Decode
String decodedUsername = URLDecoder.decode(encodedUsername);
String decodedPassword = URLDecoder.decode(encodedPassword);
A simple Google search would've done the trick...
URLEncoder should be the way to go. You only need to keep in mind to encode only the individual query string parameter name and/or value, not the entire URL, for sure not the query string parameter separator character
&
nor the parameter name-value separator character=
.String q = "random word £500 bank $"; String url = "http://example.com/query?q=" + URLEncoder.encode(q, "UTF-8");
...