How to optimize code for less Timeout errors

 

I have the feeling that i get often Timeout error when i use HTTP GET functions from windows wininet, have somebody ideas how i can optimize my code to get less or no more Timeout error from Metatarder. Is there any other function maybe that is better then HTTP GET?

The HTTP GET function looks so:


bool HttpGET(string strUrl, string& strWebPage)
{
  int hSession = InternetOpenA(AGENT, INTERNET_OPEN_TYPE_DIRECT, "0", "0", 0);

  int hReq = InternetOpenUrlA(hSession, strUrl, "0", 0,
        INTERNET_FLAG_NO_CACHE_WRITE |
        INTERNET_FLAG_PRAGMA_NOCACHE |
        INTERNET_FLAG_RELOAD, 0);

  if (hReq == 0) {
    return(false);
  }

  int     lReturn[]  = {1};
  string  sBuffer    = "";

  while (TRUE) {
    if (InternetReadFile(hReq, sBuffer, BUFSIZ, lReturn) <= 0 || lReturn[0] == 0) {
      break;
    }
    strWebPage = StringConcatenate(strWebPage, StringSubstr(sBuffer, 0, lReturn[0]));
  }

  InternetCloseHandle(hReq);
  InternetCloseHandle(hSession);

  return (true);
}


in my EA i call this HTTP GET function with every new Tick. and sometimes the EA stop and i see Timeout error message and i must restart the MetaTrader.