Encoding problem of variable handed to a GET Request

Good Evening,

I create a variable
String randomEmailAddress = ('test' + randomNr) + '@myemailtest.de'

This creates a email in the format of “test123@myemailtest.de”. Everything fine.

and hand it over to

get_response = WS.sendRequest(findTestObject('Get Inbox For Newsletter', ['emailAddress' : randomEmailAddress]))

The endpoint looks something like: https://api.testEmail.com/v1/mails?mailAddress=${emailAddress}

The problem is, due to a encoding problem, the above mentioned email address “test123@myemailtest.de” gets changed to “test123%40myemailtest.de” when the endpoint is called.

How can I prevent that from happening?

Thanks a lot!

1 Like

No. You are wrong.

The real problem is that you do not understand the specification of Uniform Resource Locators (URL). See RFC-1738, “2.2 URL Character Encoding Issues”. The spec requires a @ in a URL string must be encoded to %40.

As specified by the RFC-1738, a sender application must translate a @ to %40; and the receiver application must translate a %40 back to @. The WS.sendRequest() is encoding @ to %40 OK. Now your receiver application is supposed to decode %40 to @.

Have a look at some article that explains what “URL encoding and decoding” is. For example,

You can create a test case script as follows:

import java.nio.charset.StandardCharsets
import java.net.URLEncoder
import java.net.URLDecoder

String encodeValue(String value) {
	return URLEncoder.encode(value, StandardCharsets.UTF_8.toString())
}
String decodeEncodedValue(String encoded) {
	return URLDecoder.decode(encoded, StandardCharsets.UTF_8.toString())
}

String emailAddress = 'test123@myemailtest.de'
println encodeValue(emailAddress)

String encodedAddress = 'test123%40myemailtest.de'
println decodeEncodedValue(encodedAddress)

This code demonstrates how you can use java.net.URLEncoder class and java.net.URLDecoder class.

When I ran it, I saw in the console:

test123%40myemailtest.de
test123@myemailtest.de

Okay, first: Thanks a lot for the explanation!

I am not sure how I would be able to alter the way, sendRequest works or how the api I send to receives calls. So I have to make sure, it gets send as “@”.

And there are other things I really dont understand, for example:


Why does it get recognized correctly in the name/value pair, but not in the built url?! Feels more like a bug than a error on my side, please correct me :slight_smile:

Also: I tried around with "what happens when I send test%40test.de instead of test@test.de, and then that happens:


Why does it alters that to test%2540test.de?

Thanks a lot for your help in advance!

I don’t understand this.

I called this endpoint:


When looking at the log of the endpoint, the test@test.de does get sent correctly:
image

But in the url, its still test%40test.de

Why is it correct in the value, but not in the generated url? And do I even have the possibilities from my side to solve this issue?

You gave a string test%40test.de.
In there, a % character is translated into a string ‘%25’.
Therefore the result will be test%2540test.de

The system is working correctly as you instructed to.

No, your question doesn’t make sense.

The "value":"test@test.de" is correct, of course. At the same time, the URL with the fragment test%40test.de is valid in terms of the RFC-1738.

The fragment “test%40test” in URL is valid, but still you don’t understand it. That’s the point.

have fun with this.
as already explained, the client does the right thing, as any other sane client/browser should.

with your attempts to ‘make sure’ you only managed to break the url.

as long as you receive a right response, why bother?
you can try to reach out directly to RFC authors if the current standards does not suit your understanding.
good luck with this!

When you encode “%40” you get “%25” for “%”

% encoded → %25
40 encoded → 40
%40 encoded → %2540

More examples:

%%% encoded → %25%25%25
@@@ encoded → %40%40%40
% % % encoded → %25%20%25%20%25 (space is %20)

Now, BEFORE you post more questions, read the material behind the links that @kazurayam gave you and make sure you understand it. Until you do that, this thread could go on forever.

I think the main problem was / is that I obv. didn´t manage to formulate my problem properly (enough).
W/e thanks for your help guys, topic can be closed.

Obviously.
What you refuse to understand is:

  • in your IDE / UI browsee / whatever application you put a char or string
  • the client or whatever libraries do the encoding under the hood, as they should and send the request
  • response is received and decoded to make your eyes happy.

Attempting to manipulate it, you just make it worse. Just trust your client application this time, until you gain more knowledge on it.

will be worse if opposite happens, the url you submit is not properly encoded, or at all.

I am not quite sure where you get that I REFUSED to understand, instead of just didn´t understand due to a lack of knowledge, which i straigthened out now.

Also not quite sure if 50% of the comments in here really want to help or whether the forum here is sometimes simply used to demonstrate one’s (technical) superiority, and the actual intention is not really to help.

Like I said over 1 hr ago - topic can get closed, I won´t answer in that thread anymore. Everything is said. Thanks again I guess.

ok, appologgies for ‘refused’ but you have to realise that, we tried various approaches with you, from deeply technical to simple examples.

so… i don’t think we are that bad.
just rigurous :stuck_out_tongue:

1 Like