Hello, I need to use WebRequest to access some online information but I don't want my EA to get stuck waiting the server's response. Here is a simple script I was using to test the timeout input in the WebRequest function.
voidOnStart()
{
string url = "https://httpstat.us/200?sleep=15000";
string cookie = NULL;
string referer = NULL;
int timeout = 100; //timeout in millisecondschar data[];
int data_size = ArraySize(data);
char result[];
string result_headers;
ResetLastError();
uint start = GetTickCount();
int res = WebRequest( "GET", url, cookie, referer, timeout, data, data_size, result, result_headers);
uint delay = GetTickCount() - start;
switch( res )
{
case -1:
PrintFormat("Error in WebRequest. Error code = %d",GetLastError());
MessageBox("Add the address '"+url+"' to the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
break;
case200:
PrintFormat("Content: %s", CharArrayToString( result, 0, WHOLE_ARRAY ) );
PrintFormat("Delay: %f", delay);
PrintFormat("Hearders: %s", result_headers );
break;
default:
PrintFormat("Response code %d",res);
break;
};
}
But no matter what value (-1, 0, 500 and so on) I use for timeout, the call always waits the server's response. I am currently using MQL5 on Version 5.0 Build 3550, and the problem also seems to occur in both WebRequest overloads that appear in the documentation. It also doesn't seem to matter if you run the code above on a Script or an EA.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello, I need to use WebRequest to access some online information but I don't want my EA to get stuck waiting the server's response. Here is a simple script I was using to test the timeout input in the WebRequest function.
But no matter what value (-1, 0, 500 and so on) I use for timeout, the call always waits the server's response. I am currently using MQL5 on Version 5.0 Build 3550, and the problem also seems to occur in both WebRequest overloads that appear in the documentation. It also doesn't seem to matter if you run the code above on a Script or an EA.
Here is the result produced: