Page 1 of 1

tip_URLEncode + instead of %20

Posted: Mon Feb 21, 2022 5:49 pm
by trmpluym
Dear friends,

To use an WEB API call I am required to encode a string with URLEncode

https://en.wikipedia.org/wiki/Percent-encoding

In Harbour this can be done using the tip_URLEncode function (HBTIP Library).

So I tried the simple line below:

Code: Select all

MsgDebug( tip_URLEncode("Microsoft Office") )
I was expecting the result below:

Code: Select all

Microsoft%20Office
But instead I got:

Code: Select all

Microsoft+Office
I found out both "+" and "%20" are used to replace a SPACE character.

In the link below the statement is "%20" is more modern:

https://stackoverflow.com/questions/163 ... cter-or-20

Is there a modified version or alternative function to do the URLEncoding ?

Best regards,

Theo

Re: tip_URLEncode + instead of %20

Posted: Wed Feb 23, 2022 10:13 pm
by Claudio Ricardo
Hi, if you need only replace space with "%20", can try:
MsgDebug ( StrTran ( "Microsoft Office", " ", "%20" ) )
Or...
MsgDebug ( StrTran ( Tip_UrlEncode ( "Microsoft Office" ), "+", "%20" ) )

Re: tip_URLEncode + instead of %20

Posted: Mon Feb 28, 2022 10:49 am
by trmpluym
Hi Claudio,

Thanks for taking the time to answer my question !

In the end my problem was no problem at all because the API can also use the alternative + encoding in stead of the %20 encoding :D

Sorry for bothering !

Theo