Download MetaTrader 5
To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
xuzhe
100
xuzhe 2014.07.07 11:51 

with the page  https://www.mql5.com/en/docs/common/webrequest

 

i tried with my own script,the function works very well when i send request to public servers.

with the same code,when i send request to url like  http://127.0.0.1:8765/,it always return 4002 error code.

 

int SyncOrder(string strSymbol,string Operate)
{
   string cookie=NULL,headers;
   char post[],result[];
   int res;
   
   string url="http://www.baidu.com";
   Print("Sending request to "+ url);
   
   ResetLastError();
   
   res=WebRequest("GET",url,cookie,NULL,50,post,0,result,headers);
   
   if(res==-1)
   {
      Print("Error code =",GetLastError());
      //--- maybe the URL is not added, show message to add it
      MessageBox("Add address '"+url+"' in Expert Advisors tab of the Options window","Error",MB_ICONINFORMATION);
      
      return(-1);
   }
   else
   {
      //--- successful
      PrintFormat("Download successful, size =%d bytes.",ArraySize(result));
      //--- save data to file
      //string strResult = CharArrayToString(result,0,ArraySize(result),CP_UTF8);
      return(1);
   }
   
   return(1);   
}
Documentation on MQL5: Common Functions / WebRequest
Documentation on MQL5: Common Functions / WebRequest
  • www.mql5.com
Common Functions / WebRequest - Reference on algorithmic/automated trading language for MetaTrader 5
xuzhe
100
xuzhe 2014.07.07 11:53  

when i change it to local host address,it always return 4002

 

int SyncOrder(string strSymbol,string Operate)
{
   string cookie=NULL,headers;
   char post[],result[];
   int res;
   
   string url="http://localhost:8765";
   Print("Sending request to "+ url);
   
   ResetLastError();
   
   res=WebRequest("GET",url,cookie,NULL,50,post,0,result,headers);
   
   if(res==-1)
   {
      Print("Error code =",GetLastError());
      //--- maybe the URL is not added, show message to add it
      MessageBox("Add address '"+url+"' in Expert Advisors tab of the Options window","Error",MB_ICONINFORMATION);
      
      return(-1);
   }
   else
   {
      //--- successful
      PrintFormat("Download successful, size =%d bytes.",ArraySize(result));
      //--- save data to file
      //string strResult = CharArrayToString(result,0,ArraySize(result),CP_UTF8);
      return(1);
   }
   
   return(1);   
}
xuzhe
100
xuzhe 2014.07.07 11:54  

i add address to the allow list:

 

 

 

and the address is OK

 

Uwe Goetzke
1405
Uwe Goetzke 2014.07.07 20:11  

Try 127.0.0.1 

Maybe that localhost cannot be resolved. 

xuzhe
100
xuzhe 2014.07.08 10:10  
ugo58:

Try 127.0.0.1 

Maybe that localhost cannot be resolved. 

127.0.0.1

 

same result. 

stefanpora
5
stefanpora 2014.09.16 00:02  

Hi there,

I have the same problem. I receive 4002 but not only when connecting to localhost but also to my server on the internet. I have added the URLs to the trusted sites.

Anybody managed to fix the problem?

Stanislav Korotky
17365
Stanislav Korotky 2014.09.16 11:40  
Do you have a firewall?
MetaQuotes
Admin
24891
Renat Fatkhullin 2014.09.16 12:10  

Full domain names is allowed and only 80/433 ports.

If you want to connect to localhost, use domain like my.domain.com and setup address in hosts file.

xuzhe
100
xuzhe 2014.12.25 04:23  

thanks,you are right,port 80 works fine.

 

it should be written in document. 

/
To add comments, please log in or register