Download MetaTrader 5
To add comments, please log in or register
Sign up to publish an article and receive 200 USD
Ovo Cz
2957
Ovo Cz 2014.02.16 08:27 
Has anyone already coded url encoder in MQL4, that could be paired to the PHP urldecode()?
Ovo Cz
2957
Ovo Cz 2014.02.16 09:55  

I could not wait, here is what I used, seems to work.

   string urlencode(string value) {
      int len = StringLen(value);
      MT4String encodedValue;
      uchar characters[];
      StringToCharArray(value,characters);
      for (int i = 0; i<len ;i++) {
         encodedValue.append(StringFormat("%%%02x", characters[i]));
      }
      return encodedValue.toString();
   }
gchrmt4
356
gchrmt4 2014.02.16 10:17  
Ovo:

I could not wait, here is what I used, seems to work.

(That looks fine but, as you know, you are unnecessarily encoding alphanumeric characters, and therefore you could exceed the maximum permitted length of a URL more easily. Full list of unreserved characters at http://tools.ietf.org/html/rfc3986#section-2.3)
Ovo Cz
2957
Ovo Cz 2014.02.16 10:44  
gchrmt4:
(That looks fine but, as you know, you are unnecessarily encoding alphanumeric characters, and therefore you could exceed the maximum permitted length of a URL more easily. Full list of unreserved characters at http://tools.ietf.org/html/rfc3986#section-2.3)


Thank you, I did not perform thorough investigation. If I remember the limit was somewhere about 4k, so it is not a real threat for the purpose I need. My motto: First make it working, then optimize :)

gchrmt4
356
gchrmt4 2014.02.16 10:51  
Ovo:


Thank you, I did not perform thorough investigation. If I remember the limit was somewhere about 4k, so it is not a real threat for the purpose I need. My motto: First make it working, then optimize :)

(You are still very unlikely to hit it in real life... but if you are using Wininet then the limit is more like 2k: http://stackoverflow.com/a/3208930. In practice, allowing for "static" elements such as the hostname and path, you are probably reducing the limit to about 1k by encoding every character.)
Ovo Cz
2957
Ovo Cz 2014.02.16 13:06  
gchrmt4:
(You are still very unlikely to hit it in real life... but if you are using Wininet then the limit is more like 2k: http://stackoverflow.com/a/3208930. In practice, allowing for "static" elements such as the hostname and path, you are probably reducing the limit to about 1k by encoding every character.)


Yes, it is wininet. But 2k is still far enough to be hit.

Edit: I just performed a test, and a string of length 3M has been encoded, sent from MQL4 and returned from server to MQL4 using the standard wininet http post. So I am not sure if any limit applies to the post except the php limit. Definitively I am not aware of some 1k limit now. I think the limit only applies to the url alone but not the post data included.

In addition I got a proof that strings >3M are working in MQL4 :)

/
To add comments, please log in or register