Metatrader 4 not making webrequests properly on a linux server
Metatrader 4 not making webrequests properly on a linux server
Loading saved threads...
Eqan Ahmad · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Eqan Ahmad
Original post: https://stackoverflow.com/questions/78143612
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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.sstatic.net/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
enter image description here
and funny thing is I added these URLs in the experts tab of the mt4
enter image description here
Quote
Report
Eqan Ahmad · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Eqan Ahmad
Original post: https://stackoverflow.com/a/78261172
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have resolved the issue. It has been found that Windows server or Ubuntu server running Wine doesn't support Wininet:
https://learn.microsoft.com/en-us/troubleshoot/developer/browsers/development-website/wininet-not-supported-in-services
So I would like to advice people facing a similar issue to use WebRequest which uses WinHTTP under the hood which is supported on Windows server and Ubuntu server.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Eqan Ahmad Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/78261172 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have resolved the issue. It has been found that Windows server or Ubuntu server running Wine doesn't support Wininet: https://learn.microsoft.com/en-us/troubleshoot/developer/browsers/development-website/wininet-not-supported-in-services So I would like to advice people facing a similar issue to use WebRequest which uses WinHTTP under the hood which is supported on Windows server and Ubuntu server.
Checking account access…