Can you tell me if it is possible to know the length of a file before it is read? This is to be able to make an estimate of the percentage of loaded data in case of large volumes, slow speeds.
Can you tell me if it is possible to know the length of a file before it is read? This is to be able to estimate the percentage of data downloaded in case of large volumes, slow speeds.
I think you can. and you will find it in the msdn description of wininet.dll.
Can you tell me if it is possible to know the length of a file before it is read? This is to be able to make an estimate of the percentage of loaded data in case of large volumes, slow speeds.
Can you tell me if it is possible to know the length of a file before it is read? This is to be able to make an estimate of the percentage of downloaded data in case of large volumes, slow speeds.
There is a possibility if the server reports the length of the content.
To get information about the request you can use the HttpQueryInfo function from wininet.dll - this function returns the required information to the specified array in string form.
Example of use:
in the #import section, add a description:
int HttpQueryInfoW(int hRequest,int dwInfoLevel,uchar &lpvBuffer[],int &lpdwBufferLength,int &lpdwIndex);
also add
#define HTTP_QUERY_CONTENT_LENGTH 5
then in the code after calling InternetOpenUrlW and getting hURL you need to add the code:
int BufLen=2048; int ind=0; uchar buf0[2048]; string s=""; int ContentSize_HttpQueryInfoW=0; int iRes; iRes=HttpQueryInfoW(hURL,HTTP_QUERY_CONTENT_LENGTH,buf0,BufLen,ind); if(iRes<=0) { Print("Error in call of HttpQueryInfoW()"); } else { s=""; for(int k=0;k<BufLen;k++) { s=s+CharToString(buf0[k]);} Print("HTTP_QUERY_CONTENT_LENGTH:",s); if (StringLen(s)>0) ContentSize_HttpQueryInfoW=StringToInteger(s); Alert("Content size=",ContentSize_HttpQueryInfoW); }
in our test example from yandex.ru we get "Content size= 44649", which corresponds to the size of the downloaded file. i.e. before the start of the download (InternetReadFile) we know the length of the content.
Added this feature to the current version of the script.
Thank you for the effort!
It works perfectly!
When I try to run it the metatrader closes with a fatal error. Any solution?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
WININET_TEST:
Here is a simple example that shows how to download page(file) from Internet using the wininet.dll library.
The WININET_TEST.mq5 script is a modified version of script s_wininet.mq4, published by Integer in MQL4.Codebase.To see how does it works, don't forget to "Allow DLL imports" in the options of the client terminal and execute it at any chart.
Author: MetaQuotes