GrabWeb not working on MT4 Build 600 - page 3

 
WDholic:


may be you using u char

in my script i using string


Yes that was the issue. Now it compiles fine with v604. So basically we need to use InternetOpenW and InternetOpenUrlW and concatenate the string the same way as before.

 
bennyHanna:


Yes that was the issue. Now it compiles fine with v604. So basically we need to use InternetOpenW and InternetOpenUrlW and concatenate the string the same way as before.

I have been using the code above, developed by WDHolic, successfully since build 600 came along (thanks very much :-)).  Unfortunately, when I happened to recompile the code today, under build 830, I found that it no longer works.  I wonder if some kind person can suggest a tweak to get it working again. The code I'm using is as follows:

string secData="";
   
if (!GrabWeb(secURL, secData))
{
   showDebug("Unable to access user file");
   return(1);  
}
.
.
.
.
#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
 
bool GrabWeb(string strUrl, string& strWebPage)
{
  
    int HttpOpen = InternetOpenW(" ", 0, " "," ",0 ); 
    int HttpConnect = InternetConnectW(HttpOpen, "", 80, "", "", 3, 0, 1); 
    int HttpRequest = InternetOpenUrlW(HttpOpen,strUrl, NULL, 0, 0, 0);
   
   int read[1];
   string Buffer = " ";
 
   while (true)
   {
      InternetReadFile(HttpRequest, Buffer, StringLen(Buffer), read);
      if (read[0] > 0) strWebPage = strWebPage + StringSubstr(Buffer, 0, read[0]);
      else             break;
   }
   
   if (HttpRequest > 0) InternetCloseHandle(HttpRequest); 
   if (HttpConnect > 0) InternetCloseHandle(HttpConnect); 
   if (HttpOpen > 0) InternetCloseHandle(HttpOpen);  
 
   return(true);
}

 

It now appears to just return spaces.

Any help would be most gratefully received.  Thanks in anticipation,

Greg 

 
Any reason not to use WebRequest instead ?
 
ydrol:
Any reason not to use WebRequest instead ?

Only that Grabweb is the first method I came across a few years back and it's been easier to stick with it than investigate other options!  I will have a look at WebRequest and see if I can build it into my code.  Many thanks for the suggestion - I'll post back with my experiences - hopefully successful :-)

Thanks,

Greg 

 
ydrol:
Any reason not to use WebRequest instead ?

I use WebRequest in my news alerter, but WebRequest does suffer one shortcoming which won't suit everyone: it can only be used in an EA.

From WebRequest Documentation: 

The WebRequest() function is asynchronous, which means its breaks the program execution and waits for the response from the requested server. Since the delays in receiving a response can be large, the function is not available for calls from the indicators, because indicators run in a common thread shared by all indicators and charts on one symbol. Indicator performance delay on one of the charts of a symbol may stop updating of all charts of the same symbol.

 
honest_knave:

I use WebRequest in my news alerter, but WebRequest does suffer one shortcoming which won't suit everyone: it can only be used in an EA.

The WebRequest() function is asynchronous, which means its breaks the program execution and waits for the response from the requested server. Since the delays in receiving a response can be large, the function is not available for calls from the indicators, because indicators run in a common thread shared by all indicators and charts on one symbol. Indicator performance delay on one of the charts of a symbol may stop updating of all charts of the same symbol.

 

Should be synchronous.
 
angevoyageur:
Should be synchronous.

My current requirement is in an EA, so WebRequest will probably be the short-term answer.  

I do, however, have a number of indicators that access the news, which means I'll have to try and work out what to change in Grabweb, if I want them to continue to be maintainable.   I wonder if the information in this article will provide the answer: https://www.mql5.com/en/articles/73 ?

 
gregspinner:

My current requirement is in an EA, so WebRequest will probably be the short-term answer.  

I do, however, have a number of indicators that access the news, which means I'll have to try and work out what to change in Grabweb, if I want them to continue to be maintainable.   I wonder if the information in this article will provide the answer: https://www.mql5.com/en/articles/73 ?

 

I think I've found the answer - and it was in the article mentioned above.  The GrabWeb code now looks as follows:

#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 InternetReadFile(int, uchar &sBuffer[], int, int& OneInt);
   int InternetCloseHandle(int); 
   
#import
 
bool GrabWeb(string strUrl, string& strWebPage)
{
  
    int HttpOpen = InternetOpenW(" ", 0, " "," ",0 ); 
    int HttpConnect = InternetConnectW(HttpOpen, "", 80, "", "", 3, 0, 1); 
    int HttpRequest = InternetOpenUrlW(HttpOpen,strUrl, NULL, 0, 0, 0);
   
   /*int read[1];
   string Buffer = " ";
 
   while (true)
   {
      InternetReadFile(HttpRequest, Buffer, StringLen(Buffer), read);
      if (read[0] > 0) strWebPage = strWebPage + StringSubstr(Buffer, 0, read[0]);
      else             break;
   }*/
   
   uchar ch[500];
   string toStr="";
   int dwBytes,h;
   while(InternetReadFile(HttpRequest,ch,500,dwBytes))
   {
      if(dwBytes<=0) break;
      toStr=toStr+CharArrayToString(ch,0,dwBytes);
   }
   
   strWebPage=toStr;   
   
   if (HttpRequest > 0) InternetCloseHandle(HttpRequest); 
   if (HttpConnect > 0) InternetCloseHandle(HttpConnect); 
   if (HttpOpen > 0) InternetCloseHandle(HttpOpen);  
 
   return(true);
}

 

Basically... 

1) changed the definition of InternetRead to use an indirect reference to a uchar array for the data, and also to use a direct simple int variable for the count.

2) made the InternetRead function use a uchar array, and then converted the populated array to a string.

I'm not too sure what effect the size of the uchar array has.  It seems to read the whole web page (FFCal XML for example) regardless, and that's bigger than 500 bytes.  Is it just blatting over the next n bytes of memory, or is the system clever enough to dynamically allocate storage?  hopefully, the latter!

Cheers,

Greg 

 
The answer was also on the first page of this topic. Thanks for sharing.
 
thili55:

This code has worked flawlessly for me up until testing it in MT4 build 600, where it no longer verifies accounts from my server.


Hi guys, please what is this code all about, is it an indicator or EA? I tried running it in mql4 editor and I got the following error message:

'User - undeclared identifier'

It is actually referring to the following line of code:


(Line: 112)    GrabWeb("http://www.website.com/query.php?accountnumber="+AccountNumber()+"&login="+User, answer);


How can declare the "User" to be accepted by the program or what can I replace the "User" with?

I am using Windows 8.1, 64 bit OS, and MT4 version 4.00, build 1010.

Thank you in advance.