Richard
Richard

Reputation: 8935

Encoding a URI for a RESTful Service

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 protected], 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

Upvotes: 5

Views: 1096

Answers (3)

Lukas Abfalterer
Lukas Abfalterer

Reputation: 104

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

var encodedData = window.btoa("[email protected]"); // 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));

Upvotes: 1

Richard
Richard

Reputation: 8935

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

return this.http.get(this.BASE_URI + '/list/email/' + email + '/')

Upvotes: 1

Văn Tuấn Phạm
Văn Tuấn Phạm

Reputation: 659

You can use:

/somepath/{variable:.+}

Upvotes: 0

Related Questions