//+------------------------------------------------------------------+ //| WebRequest_00.mq4 | //| amenbo | //| 泉の森の弁財天池 | //+------------------------------------------------------------------+ #property copyright "amenbo" #property link "泉の森の弁財天池" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { string cookie=NULL,headers; char post[],result[]; int res; //--- for working with server you need to add "https://www.google.com/finance" //--- to the list of the allowed URLs (Main menu->Tools->Options, "Expert Advisors" tab) string google_url="https://www.google.com/finance"; //--- reset last error ResetLastError(); //--- load html page from Google Finance int timeout=5000; //--- timeout less than 1000 (1 sec.) is not sufficient for slow Internet speed res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers); //--- check errors if(res==-1) { Print("Error code =",GetLastError()); //--- maybe the URL is not added, show message to add it MessageBox("Add address '"+google_url+"' in Expert Advisors tab of the Options window","Error",MB_ICONINFORMATION); } else { //--- successful PrintFormat("Download successful, size =%d bytes.",ArraySize(result)); //--- save data to file int filehandle=FileOpen("GoogleFinance.htm",FILE_WRITE|FILE_BIN); //--- check if(filehandle!=INVALID_HANDLE) { //--- write result[] array to file FileWriteArray(filehandle,result,0,ArraySize(result)); //--- close file FileClose(filehandle); } else Print("Error in FileOpen. Error code=",GetLastError()); } }