GrabWeb not working on MT4 Build 600 - page 2

 
gchrmt4:
...However, that script should still work for retrieving short server responses such as the results of a licensing query. It's only got issues if the size of the server's response exceeds 1KB-ish.

Thanks, this worked perfectly!
 

Hi thili55,

Can you help us and post your solution for getting the grabWeb() to work with build 600? I think a lot of people would be interested in having FFCal working with build 600.

Many thanks

 
bennyHanna:

Can you help us and post your solution for getting the grabWeb() to work with build 600? I think a lot of people would be interested in having FFCal working with build 600.

See the post which thili55 is replying to - but note that there currently seem to be string-handling issues in v600 which may affect downloading as much data as the FF calendar.
 
gchrmt4:
See the post which thili55 is replying to - but note that there currently seem to be string-handling issues in v600 which may affect downloading as much data as the FF calendar.


Thanks for your reply. So we will need to wait for a fix of v600 before devising a solution for grabWeb correct? Or was a fix provided in v603?

 
bennyHanna:


Thanks for your reply. So we will need to wait for a fix of v600 before devising a solution for grabWeb correct? Or was a fix provided in v603?

Seems you don't understand the problem. The code has to be fixed to take into account the change in mql4.
 

Here is the GrabWeb function updated to run on v600. It now uses InternetOpenW and InternetOpenUrlW and the conversion of unicode. It does get the XML files OK but the files all have NULL data. See the Print statement for StrWebPage in the code. If you look at the outputted data it is garbage while strThisRead has valid data. Can someone have a look and see if they can spot a fix? It follows the fix on this thread: https://www.mql5.com/en/forum/149360

Just copy and paste the code in your FFCal.mq4 and compile with v600 MT4 and run (please edit out the items that do not belong in your version so that it compiles).

bool bWinInetDebug = false;

#define READURL_BUFFER_SIZE   1000

#import "wininet.dll"
   int InternetOpenW(string, int, string, string, int);
   int InternetOpenUrlW(int, string, string, int, int, int);
   int InternetReadFile(int, uchar & arr[], int, int & arr[]);
   int InternetCloseHandle(int);
#import

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
bool GrabWeb(string strUrl, string& strWebPage)
   {
           int     hInternet;
           int     hInternetUrl;
           bool    bSuccess = false;
           
           // Get an internet handle
           hInternet = InternetOpenW("mt4", 0 /* 0 = INTERNET_OPEN_TYPE_PRECONFIG */, NULL, NULL, 0);
        
           if (bWinInetDebug) 
                   Log("hInternet: " + hInternet);   
                   
           if (hInternet == 0) 
         {     
            Message = Symbol() + " " + IndicatorName + " Error 890 - Unable to get an Internet Handle!";
            Print(Message);
            Alert(Message);                                     
            HealthBuffer[0] = Error_state; 
            bSuccess = false;
         }
      else
         {         
            // Get a URL handle
            hInternetUrl = InternetOpenUrlW(hInternet, NewsURL, NULL, 0, 0, 0);
            
           if (bWinInetDebug) 
                   Log("hInternetUrl: " + hInternetUrl);   

           if (hInternetUrl == 0) 
               {     
                  Message = Symbol() + " " + IndicatorName + " Error 891 - Unable to get a URL handle!";
                  Print(Message);
                  Alert(Message);                           
                  HealthBuffer[0] = Error_state; 
                  bSuccess = false;
               }
            else
               {
                  Print("Reading URL: " + strUrl);
                       
                       bool bKeepReading = true;
                  
                  while (bKeepReading) 
                     {                    
                                            int   lReturn[1];
                                            uchar arrReceive[];
                                            
                                            ArrayResize(arrReceive, READURL_BUFFER_SIZE + 1);
                        
                        int success = InternetReadFile(hInternetUrl, arrReceive, READURL_BUFFER_SIZE, lReturn);
            
                        if (success == 0) 
                           {
                              Message = Symbol() + " " + IndicatorName + " Error 892 - Unable to read News Database WebPage!";
                              Print(Message);
                              Alert(Message);                                  
                              HealthBuffer[0] = Error_state; 
                              bKeepReading = false;
                              bSuccess = false;
                           }
                        else 
                           {
                                   if (bWinInetDebug) 
                                           Log("success: " + success);
                                   
                                   if (bWinInetDebug) 
                                           Log("arrReceive: " + arrReceive[0]);    

                                   if (bWinInetDebug) 
                                           Log("lReturn: " + lReturn[0]);
                                   
                              // InternetReadFile() has succeeded, but we may be at the end of the data 
                              if (lReturn[0] == 0) 
                                 {
                                    if (bWinInetDebug) 
                                       Print("Reached end of data");
                                    
                                    bKeepReading = false;
                                    bSuccess = true;
                                 } 
                              else 
                                 {
                                    // Convert the data from Ansi to Unicode using the built-in MT4 function
                                    string strThisRead = CharArrayToString(arrReceive, 0, lReturn[0], CP_UTF8);
                                    strWebPage = StringConcatenate(strWebPage, strThisRead);  // <-- PROBLEM HERE ON FIRST USE ONLY IN EACH MT4 SESSION
                                 Print ("------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>> strWebPage : ", strWebPage);  // this shows garbage!
				}
                           }
                     }
               }
         }

      Print("Closing URL web connection");
           success = InternetCloseHandle(hInternetUrl);
           
           if (success == 0) 
         {     
            Message = Symbol() + " " + IndicatorName + " Error 896 - Unable to close URL handle!";
            Print(Message);
            Alert(Message);                                  
            HealthBuffer[0] = Error_state; 
            bSuccess = false;
         }
      else
         {
                 success = InternetCloseHandle(hInternet);

           if (success == 0) 
               {     
                  Message = Symbol() + " " + IndicatorName + " Error 898 - Unable to close Internet Handle!";
                  Print(Message);
                  Alert(Message);                                  
                  HealthBuffer[0] = Error_state; 
                  bSuccess = false;
               }
              }
              
           return(bSuccess);
   
   } // end of function
 

i try to make a GRABWEB script

very Simple.. and works fine in build 604

 
#import  "Wininet.dll"
   int InternetOpenW(string, int, string, string, int);
   int InternetConnectW(int, string, int, string, string, int, int, int); 
   int HttpOpenRequestW(int, string, string, int, string, int, string, int); 
   int InternetOpenUrlW(int, string, string, int, int, int);
   int InternetReadFile(int, string, int, int& OneInt[]);
   int InternetCloseHandle(int); 
   
#import
 
int start()
{
   string URL="http://www.forexfactory.com/ff_calendar_thisweek.xml";
  
    int HttpOpen = InternetOpenW(" ", 0, " "," ",0 ); 
    int HttpConnect = InternetConnectW(HttpOpen, "", 80, "", "", 3, 0, 1); 
    int HttpRequest = InternetOpenUrlW(HttpOpen,URL, NULL, 0, 0, 0);
   
   int read[1];
   string Buffer = " ";
   string NEWS = "";
 
   while (true)
   {
      InternetReadFile(HttpRequest, Buffer, StringLen(Buffer), read);
      if (read[0] > 0) NEWS = NEWS + StringSubstr(Buffer, 0, read[0]);
      else             break;
   }
   
 
   
   if (HttpRequest > 0) InternetCloseHandle(HttpRequest); 
   if (HttpConnect > 0) InternetCloseHandle(HttpConnect); 
   if (HttpOpen > 0) InternetCloseHandle(HttpOpen);  
     MessageBox(NEWS, "HTTP READ:" );     //  i show the result via message box
 
   //----
   return(0);
}
  
//+------------------------------------------------------------------+
 
WDholic:

i try to make a GRABWEB script

very Simple.. and works fine in build 604


May I ask how you are overcoming this compiling error with v604 for this line of code:

InternetReadFile(HttpRequest, Buffer, StringLen(Buffer), read);

Error: 'Buffer' - parameter conversion not allowed

Please check your MT4 version and try again!



 
bennyHanna:


May I ask how you are overcoming this compiling error with v604 for this line of code:

Error: 'Buffer' - parameter conversion not allowed

Please check your MT4 version and try again!




There is no such error on my v604 and v600 with this program no errors and no warnings the file was downloaded correctly
WDholic:

i try to make a GRABWEB script

very Simple.. and works fine in build 604

I tried, it works for me also.... thank you
 
bennyHanna:


May I ask how you are overcoming this compiling error with v604 for this line of code:

Error: 'Buffer' - parameter conversion not allowed

Please check your MT4 version and try again!




may be you using u char

 int InternetReadFile(int, uchar & arr[], int, int & arr[]);

in my script i using string

int InternetReadFile(int, string, int, int& OneInt[]); 
Reason: