WebRequest Error 5200 Despite Correct Settings and Working Server

 
Dear Friends,

I am reaching out for assistance with an issue I've been experiencing while using the WebRequest function in an MQL4 script/Expert Advisor. I keep receiving an "Invalid URL" error, with the error code 5200, despite my checks indicating that all settings are correct.

Here's a brief rundown of the situation:

I'm trying to send a POST request to the URL http://10.211.55.2:5000/ai using the WebRequest function in MQL4.

I've verified the server is working correctly as I'm able to successfully send a request using a curl command from the command line and get the expected response. Here's the command that works:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "text=KUMORO" http://10.211.55.2:5000/ai

In MetaTrader 4, I have added the URL http://10.211.55.2:5000 to the 'Allowed URLs for WebRequest' list under 'Tools' -> 'Options' -> 'Expert Advisors'.

I've checked my firewall and antivirus settings to ensure there are no outgoing connection blocks that could prevent MetaTrader 4 from connecting to my server.

Here's the relevant MQL4 code:
 void OnTick() {
    string url = "http://10.211.55.2:5000/ai";
    int timeout = 5000;  // Time in milliseconds to wait for a response

    string headers = "Content-Type: application/x-www-form-urlencoded";
    string post_data = "text=KUMORO";
    
    char post[], response[];
    StringToCharArray(post_data, post);
    string result;

    int res = WebRequest("POST", url, headers, timeout, post, response, result);
    
    if (res == -1) {
        Print("WebRequest failed. Error code: ", GetLastError());
    } else {
        Print("Server responded: ", result);
    }
} 
Despite following all the recommended steps, I still encounter the Error 5200 whenever I attempt to execute the script.
2023.06.15 23:05:41.270 TestCnxtion AUDUSDb,H1: WebRequest failed. Error code: 5200
(TestCnxtion is my EA, attach to AUDUSDb chart in H1 TF)

Try manually using ping  : ping 10.211.55.2

Pinging 10.211.55.2 with 32 bytes of data:
Reply from 10.211.55.2: bytes=32 time<1ms TTL=64
Reply from 10.211.55.2: bytes=32 time<1ms TTL=64
Reply from 10.211.55.2: bytes=32 time<1ms TTL=64
Reply from 10.211.55.2: bytes=32 time<1ms TTL=64

Ping statistics for 10.211.55.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

Using Curl : curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "text=KUMORO" http://10.211.55.2:5000/ai
Received text (POST - Form): KUMORO

I would appreciate any assistance or insight you guys could provide to help me resolve this issue.
Thank you in advance for your support.

Best Regards,
Kumoro
[Deleted]  

Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 

Isn't WebRequest() restricted to port 80 and 443 ?

Forum on trading, automated trading systems and testing trading strategies

WebRequest...

Rashid Umarov , 2014.11.10 09:27

You cannot specify the port yourself. The rule applies:

- if the address starts with https://, then port 443. Otherwise, port 80.