Metatrader 4 not making webrequests properly on a linux server

119 views Asked by At

I'm currently hosting metatrader 4 on a linux server where the trading bot on the metatrader 4 performs webrequests. The same bot works fine on my own system and my friends system. But on the server it doesn't get anything from the webrequests. (https://i.stack.imgur.com/mPVz3.png)

Environment Information:

  • Ubuntu Linux
  • Server by Contabo Servers
  • MT4 running via wine on linux

Tried so far

The following is the webrequest code which runs fine on all my personal systems but unfortunately not on contabo servers:

int InternetGetFile(string url,string &content)
  {
//--- Init
   content=NULL;

//--- Create connection
   int httpconnect=0;
   int httprequest=0;
   int httpopen=Wininet::InternetOpenW("InternetGetFileMQL",0," "," ",0);
   int e=kernel32::GetLastError();
   if(e==0)
     {
      bool flag=Wininet::DeleteUrlCacheEntryW(url);
      httprequest=Wininet::InternetOpenUrlW(httpopen,url,NULL,0,16|10,0);
      e=kernel32::GetLastError();
      if(e==0)
        {
         //--- Define buffers
         uchar ch[512];
         string temp="";

         //--- Retrieve data from file
         int cnt=0;
         while(Wininet::InternetReadFile(httprequest,ch,512,cnt))
           {
            //e=kernel32::GetLastError();
            if(cnt<=0)
               break;
            temp=temp+CharArrayToString(ch,0,cnt);
           }
         //--- Store result
         content=temp;
        }
     }

//--- Close connection
   if(httprequest>0)
      InternetCloseHandle(httprequest);
   if(httpopen>0)
      InternetCloseHandle(httpopen);

//--- Get out and return error code
   return(e);
  }

EDIT:

I found something interesting that may help:

I replaced the previous code and tried to use the inbuilt mql4 web request function

    //--- Call WebRequest function
    string method = "GET";
    string headers = "";
    int timeout = 5000; // Timeout in milliseconds (adjust as needed)
    char data[]; // No data to send
    char result[4096]; // Fixed-size array to hold response (adjust as needed)
    string result_headers;
    
    int request = WebRequest(method, url, headers, timeout, data, result, result_headers);
    
    // Check for successful request
    if (request == 200) {
        // Copy result to content string
        content = CharArrayToString(result);

        Print("Data collected");
    } else {
        // Handle error (you may want to add more error handling)
        Print("Error: Web request failed with code ", request);
    }

    return request;

I got these error pops

enter image description here

and funny thing is I added these URLs in the experts tab of the mt4

enter image description here

0

There are 0 answers