Download MetaTrader 5
To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
Tradeing Trader
556
Tradeing Trader 2014.03.26 11:01 

Hello,

i have a function created with wininet which does read the website content into a string and i am wondering, when i change the website content then the function does not show me the new content, but when i close metatarder and start new, then he show me now the new website content, but why must i first close and restart the metatrader? Can the function not give me direct the new website content without restarting MT4?


//+------------------------------------------------------------------+
//|                                                    Indicator.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Imported functions description                                   |
//+------------------------------------------------------------------+
#import "wininet.dll"
int InternetOpenW(
                  string     sAgent,
                  int        lAccessType,
                  string     sProxyName="",
                  string     sProxyBypass="",
                  int     lFlags=0
                  );
int InternetOpenUrlW(
                     int     hInternetSession,
                     string     sUrl,
                     string     sHeaders="",
                     int     lHeadersLength=0,
                     int     lFlags=0,
                     int     lContext=0
                     );
int InternetReadFile(
                     int     hFile,
                     uchar     &sBuffer[],
                     int     lNumBytesToRead,
                     int     &lNumberOfBytesRead
                     );
int InternetCloseHandle(
                        int     hInet
                        );
#import

int hSession_IEType;
int hSession_Direct;
int Internet_Open_Type_Preconfig=0;
int Internet_Open_Type_Direct=1;


input string URL="http://www.websiteurl.net/file.php";



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
//----
  }




//+--------------------------------------------------------------------+
//|                                                                    |
//+--------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
//----
  }



//+--------------------------------------------------------------------+
//|                                                                    |
//+--------------------------------------------------------------------+
int start()
  {
//----
  
   string str=httpGET(URL);
   Print("website ",str);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int hSession(bool Direct)
{
//---
  string InternetAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";
  if(Direct)
    {
      if(hSession_Direct==0)
        {
         hSession_Direct=InternetOpenW(InternetAgent,Internet_Open_Type_Direct,"0","0",0);
        }

    return(hSession_Direct);
    }
  else
   {
      if(hSession_IEType==0)
        {
         hSession_IEType=InternetOpenW(InternetAgent,Internet_Open_Type_Preconfig,"0","0",0);
        }

    return(hSession_IEType);
   }
//---
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string httpGET(string strUrl)
{
//---
   int handler=hSession(false);
   int response= InternetOpenUrlW(handler,strUrl);
   if(response == 0)return(false);

   uchar ch[100]; string toStr=""; int dwBytes,h=-1;
   while(InternetReadFile(response,ch,100,dwBytes))
     {
      if(dwBytes<=0) break; toStr=toStr+CharArrayToString(ch,0,dwBytes);
     }

   InternetCloseHandle(response);
   return(toStr);
//---
}




qjol
3243
qjol 2014.03.26 13:43  
try to close the hSession
GreenMoney
379
GreenMoney 2014.03.26 14:05  
PlanandTrade:

Hello,

i have a function created with wininet which does read the website content into a string and i am wondering, when i change the website content then the function does not show me the new content, but when i close metatarder and start new, then he show me now the new website content, but why must i first close and restart the metatrader? Can the function not give me direct the new website content without restarting MT4?


Try forcing the InternetOpenUrl() to reload the content from the server (rather than from the cache) by setting the INTERNET_FLAG_RELOAD.
Tradeing Trader
556
Tradeing Trader 2014.04.09 07:44  
thank you, it have work with that Tip INTERNET_FLAG_RELOAD.
/
To add comments, please log in or register