5

I am trying to call a java GET RESTful service with an email address from Ionic 2 (javascript). It works fine, however when I add a dot (e.g. .com) to the email address it looses all the characters from the dot when it reaches the service.

How do I encode the URI in order to send an email address to the service please?

I am using:

'/list/email/' + encodeURIComponent(email)

but if the email address is: email@domain.com, it reaches the service as email@domain.

I have tried:

'/list/email/' + email

'/list/email/' + encodeURI(email)

'/list/email/' + encodeURIComponent(email)

all give the same result

Thanks

Richard
  • 8,193
  • 28
  • 107
  • 228

3 Answers3

1

You could try to encode your E-Mail Address to a Base64 String.

var encodedData = window.btoa("test@test.com"); // encode a string
var decodedData = window.atob(encodedData); // decode the string

That's how you can decode a Base64 String on the Server

byte[] valueDecoded= Base64.decodeBase64(bytesEncoded);
System.out.println("Decoded value is " + new String(valueDecoded));
  • Thanks Lukas. Can I decode the string in java on the server? – Richard Aug 22 '16 at 09:35
  • Of course you can decode the string on server, question on that has been answered on this thread:http://stackoverflow.com/questions/469695/decode-base64-data-in-java – gdyrrahitis Aug 22 '16 at 09:44
1

The FIX is simple. Just add a '/' on the end of the url

return this.http.get(this.BASE_URI + '/list/email/' + email + '/')
Richard
  • 8,193
  • 28
  • 107
  • 228
0

You can use:

/somepath/{variable:.+}
  • 1
    Hi Van, thanks for the answer, but I don't understand. I am doing this in a javascript function, and the syntax you use doesn't make sense to me? – Richard Aug 22 '16 at 09:23