Loading…

Url And Query String Codec

Any program that builds a URL by plain string concatenation - a webhook notifier, a Telegram alert, a custom logging endpoint - breaks the moment a parameter contains a space, an ampersand, an equals sign, or a comment field a user typed freely. The request either fails outright or silently truncates at the offending character, and the bug only shows up once somebody's comment happens to contain the wrong symbol. This header percent-encodes every reserved and non-ASCII byte per RFC 3986, leaving only the unreserved set (letters, digits, - _ . ~) untouched. Non-Latin text is handled correctly, not just tolerated: UrlEncode converts the input to UTF-8 bytes before encoding, and UrlDecode reassembles the percent-decoded bytes and interprets them as UTF-8 at the end, so Cyrillic, Uzbek diacritics or any other non-ASCII text round-trips back to the exact original string instead of turning into mojibake or question marks. Query assembly is a separate concern from encoding a single value. UrlParamsAdd builds a flat array of key/value pairs, UrlBuildQueryString encodes both the key and the value of every pair and joins them with &, and UrlBuild appends that query string to a base URL, correctly detecting whether the base already has its own ? and query fragment so it does not end up with two question marks or a missing separator. Notes and limitations - WebRequest itself is not called anywhere in this header or its demo - it only builds the string a WebRequest call would send. WebRequest also requires the target URL to be allow-listed in Tools -> Options -> Expert Advisors before it will succeed, which this library has no control over. - '+' decodes to a space in UrlDecode, matching classic form encoding. If a literal '+' character is genuinely intended in decoded output, it must be encoded as %2B by the sender - this is standard URL-encoding behaviour, not a limitation specific to this header. - Query parameter storage is a flat array with no lookup by key - it is build-only, matching what assembling a request needs. Add your own linear search if you need to read a parameter back out by name. - UTF-8 conversion uses the CP_UTF8 codepage support in StringToCharArray/CharArrayToString, present on both platforms in current terminal builds; very old MQL4 builds without UTF-8 codepage support would need ASCII-only text. - No thread or network concerns: every function is pure string manipulation.

Script · MT5 · v1.0 · Free

About Url And Query String Codec

Url And Query String Codec is a script for MetaTrader 5. MQL source code included.

Files in the download: UrlCodec.mq5.mqh, UrlCodec.txt, UrlCodecDemo.ex5, UrlCodecDemo.mq5.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · Telegram · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria