Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 6 Monaten, 3 Wochen
Letzter Beitrag:
vor 6 Monaten, 1 Woche
Beteiligte Autoren:
Sivaprakash, Peter Holemans

[WD21] URLEncode

Startbeitrag von Sivaprakash am 29.01.2017 06:20

Hello,

To send messages through an API, I need to use URLEncode function. Seems that function is not encoding the special character '&'.

My code:

sResult is string
sResult = URLEncode (EDT_Input)
Info(sResult)


For input : Nice & beatiful,
I get : Nice%20&%20beatiful

When I try @ http://www.urlencoder.org/
I get Nice%20%26%20Worthy
for the same input string. (see %26 in between %20)

Would like to know whether URLEncode function should encode ('&') to %26 or not ? What should we do to correct this problem.

Happiness Always
BKR Sivaprakash

Antworten:

Hi Sivaprakash,

It seems that in your case it should encode it to %26 (Since it is not after the ? (start params) character and since it is part of the full string you want to pass). & is a reserved character and is a parameter separator in the URL. So if you want to it to be part of a parameter value it should encode it to %26.

Again, it seems that the WX implementation of this function is half baked (like quite some other stuff)...
I don't expect you to get a fix anymore for WX21 as WX22 has all the focus now.

I can see a way to overcome this however which is at least 10 times slower:
- You break up the URL yourself into its logical components (base address, params, each param, ...)
- Next you encode each part and stick it together again into a single string

Another way is to use another development language or use an external library that does it correctly.
E.g. for .Net include library: System.Web.HttpUtility.UrlEncode(string) or System.Web.HttpServerUtility.UrlEncode(string)
(There are also other signatures of these methods to include e.g. the encoding to use etc...)

Cheers,

Peter Holemans

von Peter Holemans - am 30.01.2017 08:15
Thanks Peter Holemans,

Not interested in adding a .Net library, as few of my customers still not moving to .Net, running with old windows.

In this case, I need to write an URLEncode function to encode it properly, atleast the '&' character, as as of now, only this character is extensively used inside the message.


// I can see a way to overcome this however which is at least 10 times slower:
- You break up the URL yourself into its logical components (base address, params, each param, ...)
- Next you encode each part and stick it together again into a single string

No need of this even, as I'm constructing the URL only here. Need a way to encode the message part, that's all.


Happiness Always
BKR Sivaprakash

von Sivaprakash - am 30.01.2017 10:58
Hello,

This is a solution from another user group, converted to windev. Hope it will be useful.

m_urlencode is object OLE dynamic
m_urlencode = new object OLE "MSScriptControl.ScriptControl"
m_urlencode>>language = "javascript"
ls_arg = Replace(ls_arg,"'", "\'")
ls_arg = "encodeURIComponent ('" + ls_arg + "')"
EDT_output = m_urlencode>>Eval (ls_arg)
delete m_urlencode

CASE ERROR:
Info("Some unexpected error")
CASE EXCEPTION:
Info("Exception")

Happiness Always
BKR Sivaprakash

von Sivaprakash - am 13.02.2017 07:28
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.