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
- I have enabled all webrequest options within the metatrader 4.
- I tried unblocking the port 443 using ufw but didn't get anything out of it.
- Tried these articles as well
- https://www.malibal.com/guides/how-to-open-ports-on-ubuntu/#:~:text=For%20example%2C%20if%20you%20want,need%20to%20open%20port%2022
- https://linuxconfig.org/how-to-open-allow-incoming-firewall-port-on-ubuntu-22-04-jammy-jellyfish https://contabo.com/blog/how-to-setup-a-software-firewall-in-linux-and-windows/
- https://www.malibal.com/guides/how-to-open-ports-on-ubuntu/#:~:text=For%20example%2C%20if%20you%20want,need%20to%20open%20port%2022
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
and funny thing is I added these URLs in the experts tab of the mt4