B4J Question [SOLVED] How To Send URL with '=' And Not Get Special Characters

cklester

Well-Known Member
Licensed User
Uh. OK. So...

After thinking I resolved my URL problem in this thread, turns out the original problem I was trying to solve has not been resolved.

=50 turns into the 'P' character, and creates this:

B4X:
http://127.0.0.1:51042/confirm?codePrtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q

instead of

B4X:
http://127.0.0.1:51042/confirm?code=50rtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q

Ugh! ?

How do I filter out the bad characters? Anybody have any ideas?
 

cklester

Well-Known Member
Licensed User
OK, I'm resolving this with a bit of a cheat...

I'll just prepend a set of legitimate, non-error-generating letters to the beginning of the code.

So, instead of the code being

B4X:
50rtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q

which will cause problems when put in the URL like,

B4X:
http://127.0.0.1:51042/confirm?code=50rtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q

which becomes

B4X:
http://127.0.0.1:51042/confirm?codePrtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q

in the user's email, I will just prepend valid characters like this:

B4X:
http://127.0.0.1:51042/confirm?code=XYZ50rtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q

Solved! (?) ?
 
Upvote 0

cklester

Well-Known Member
Licensed User
Maybe I don't get it but... What about to url- encode the (url)string? (Stringutils)

Well, I didn't find that functionality, so I had to come up with something clever! ?

But I tested your suggestion, and it doesn't work. The encoded URL does not render as a legitimate URL in the email.

Screenshot of email with URL-encoded link:

 
Upvote 0

Dadaista

Active Member
Licensed User
Longtime User
Can you try?

B4X:
Dim sBody As String = ""
Dim SMTP As SMTP
dim sHTTP as string = "http://127.0.0.1:51042/"
dim token as string = "XYZ50rtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q"

sBody = "<html><head><title>Your Title</title></head>"
    sBody = sBody & "<body> click link or copy and paste in your browser "
    sBody = sBody & "<a href=" & sHTTP & "confirm?code=" & token.Trim & ">" & sHTTP & "confirm?code=" & token.Trim & "</a>"
    sBody = sBody & "</body></html>"
    sBody = sBody.Replace("=", "&#61;")
    SMTP.Body = sBody
    SMTP.Send
 
Upvote 0

cklester

Well-Known Member
Licensed User

Yes, I can give it a try. I'm sending the emails in plain text, though, not HTML.

Also, the token should be "50rtTB2vEIdd20UgD4Puk2tcjBuQsdY9Q" to duplicate the problem.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User

Oh I wonder if the email client is santising the URL?

The %3D should be recognised by the browser - the email client shouldnt care what the link is (unless its fiddling with the link).

So if you click on the link above, what shows in the address bar in the browser?
 
Upvote 0

cklester

Well-Known Member
Licensed User
Here's what I get when I click that link:


That's in the Brave browser. Not sure what others would do with it. I should check it out.

It's a coincidence that the B4X forum bookmark is right there. ?

P.S. When I click to view the raw email source, the link is correct.

P.P.S. It does not work in Edge.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…