简体   繁体   English

编码RESTful服务的URI

[英]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). 我试图用Ionic 2(javascript)的电子邮件地址调用java GET RESTful服务。 It works fine, however when I add a dot (eg .com) to the email address it looses all the characters from the dot when it reaches the service. 它工作正常,但是当我在电子邮件地址中添加一个点(例如.com)时,它会在到达服务时丢失点中的所有字符。

How do I encode the URI in order to send an email address to the service please? 如何编码URI以便向服务发送电子邮件地址?

I am using: 我在用:

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

but if the email address is: email@domain.com , it reaches the service as email@domain . 但如果电子邮件地址是: email@domain.com ,它将以email@domain到达服务。

I have tried: 我试过了:

'/list/email/' + email

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

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

all give the same result 都给出了相同的结果

Thanks 谢谢

You could try to encode your E-Mail Address to a Base64 String. 您可以尝试将您的电子邮件地址编码为Base64字符串。

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 这就是你如何解码服务器上的Base64字符串

byte[] valueDecoded= Base64.decodeBase64(bytesEncoded);
System.out.println("Decoded value is " + new String(valueDecoded));

The FIX is simple. FIX很简单。 Just add a '/' on the end of the url 只需在网址末尾添加“/”即可

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

您可以使用:

/somepath/{variable:.+}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM