grabweb
Download scriptThis script is designed to establish a bridge between the MetaTrader trading platform and the external internet. Its primary purpose is to allow the software to "reach out" to a specific website to retrieve data or interact with an online resource.
How the Logic Works
The script functions through a series of automated steps that mimic how a web browser behaves:
1. Establishing a Connection Identity To successfully communicate with a website, the script prepares a "User Agent." This is essentially a digital fingerprint that tells the destination website what kind of device or software is trying to access it. In this case, it identifies itself similarly to an older version of the Internet Explorer browser.
2. Selecting the Connection Path The logic includes different methods for connecting to the internet. It can choose between using a "preconfigured" setting (like those saved in your system's internet options) or a "direct" connection. This ensures that the script has flexibility in how it navigates through your network settings to reach the target address.
3. Opening the Web Portal Once the identity and path are set, the script targets a specific web address (defined at the top of the configuration). It opens a communication channel to that URL, much like typing an address into a browser and hitting enter.
4. Retrieving the Information After the connection is successfully opened, the script performs a "read" operation. It attempts to grab a small specific amount of data from the website. Think of this as opening a book to a specific page and reading just a few characters.
5. Finalizing and Reporting Once the data has been captured (or an attempt has been made), the script systematically closes the connection to keep the system clean and efficient. Throughout this entire process, it records its progress and any results—such as success messages or specific pieces of text—directly onto the trading platform's dashboard for the user to see.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| grabweb.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern string sUrl = "http://megadelfi.com";
int hSession_IEType;
int hSession_Direct;
int Internet_Open_Type_Preconfig = 0;
int Internet_Open_Type_Direct = 1;
int Internet_Open_Type_Proxy = 3;
int Buffer_LEN = 13;
#import "wininet.dll"
int InternetOpenA(
string sAgent,
int lAccessType,
string sProxyName="",
string sProxyBypass="",
int lFlags=0
);
int InternetOpenUrlA(
int hInternetSession,
string sUrl,
string sHeaders="",
int lHeadersLength=0,
int lFlags=0,
int lContext=0
);
int InternetReadFile(
int hFile,
string sBuffer,
int lNumBytesToRead,
int& lNumberOfBytesRead[]
);
int InternetCloseHandle(
int hInet
);
int hSession(bool Direct)
{
string InternetAgent;
if (hSession_IEType == 0)
{
InternetAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";
hSession_IEType = InternetOpenA(InternetAgent, Internet_Open_Type_Preconfig, "0", "0", 0);
hSession_Direct = InternetOpenA(InternetAgent, Internet_Open_Type_Direct, "0", "0", 0);
}
if (Direct)
{ return(hSession_Direct); }
else
{ return(hSession_IEType); }
}
int start()
{
Print("fake start");
}
int init()
{
int hInternet;
string iResult;
int lReturn[]={1};
string sBuffer="x";
hInternet = InternetOpenUrlA(hSession(FALSE), sUrl, "0", 0, 67108864, 0);
Print("hInternet: " + hInternet);
iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn);
Print("iResult: " + iResult);
Print("lReturn: " + lReturn[0]);
iResult = InternetCloseHandle(hInternet);
Print("iResult: " + iResult);
Print("sBuffer: " + sBuffer);
Comment("sBuffer: " + sBuffer);
return(0);
}
//+------------------------------------------------------------------+
Comments