sunmingtao / sample-code

3 stars 4 forks source link

How to encode an ampersand in an URL as request parameter in Java and javascript #227

Closed sunmingtao closed 3 years ago

sunmingtao commented 3 years ago

for example

http://localhost:8080/auth?client_id=trove&redirect_uri=http://localhost:8082/ui/delivery/menu-internal?deliverySystem=newspapers-gazettes&callback=callbackMethod

where &callback=callbackMethod is part of redirect_uri

sunmingtao commented 3 years ago

Java:

String redirectUrl = http://localhost:8082/ui/delivery/menu-internal?deliverySystem=newspapers-gazettes&callback=callbackMethod
String encodedRedirectUrl = URLEncoder.encode(redirectUrl, "UTF-8");

Javascript:

encodeURIComponent(redirectUrl)