Download MetaTrader 5
To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
donato
21
donato 2016.09.14 09:26 

Goodmorning

i made a code in javascript that if i visit this page from browser it open a position in binary.com.

But if i made a webrequest from mt4, it doesn't work also if i get result 200 on webrequest and 4000 error of mt4.

Some one can help me? 

  string params="";
      char data[];
      int timeout=5000;
      string url="http://www.mywebsite.it/index.html";
      int data_size=StringLen(params);
      StringToCharArray(params,data,0,data_size);

      uchar result[];
      string result_headers;

      //--- application/x-www-form-urlencoded
     int res=WebRequest("GET",url+params,NULL,NULL,timeout,data,data_size,result,result_headers);
     Alert("Res  "+res+"  Error code =",GetLastError());
Files:
Fernando Carreiro
1468
Fernando Carreiro 2016.09.14 10:04  

You must first set permissions on MetaTrader's Options in order to allow access to that website. Go to the "Tools->Options" (or Ctrl+O) and then go to the "Expert Advisors" tab. At the very end of those options, to will find and have to enable the "Allow WebRequest for the listed URL:" and then proceed to add the URL of the site.

NB! Also, depending on the data being retrieved, you may need to use the 2nd version of WebRequest as the first one is only valid for form data (Content-Type: application/x-www-form-urlencoded).

WebRequest

2. Sending a request of any type specifying the custom set of headers for a more flexible interaction with various Web services.

int  WebRequest(
   const string      method,           // HTTP method
   const string      url,              // URL
   const string      headers,          // headers 
   int               timeout,          // timeout
   const char        &data[],          // the array of the HTTP message body
   char              &result[],        // an array containing server response data
   string            &result_headers   // headers of server response
   );
donato
21
donato 2016.09.14 10:15  
FMIC:

You must first set permissions on MetaTrader's Options in order to allow access to that website. Go to the "Tools->Options" (or Ctrl+O) and then go to the "Expert Advisors" tab. At the very end of those options, to will find and have to enable the "Allow WebRequest for the listed URL:" and then proceed to add the URL of the site.

Also, depending on the data being retrieved, you may need to use the 2nd version of WebRequest as the first one is only valid for form data (Content-Type: application/x-www-form-urlencoded).

I added the url at list yet but doesn't work.  

Now doesn't matter data retrieved, also if don't come back nothing is good. The important is to open the position. How you programm the second version on this code?

 

Fernando Carreiro
1468
Fernando Carreiro 2016.09.14 11:13  
duddas90: I added the url at list yet but doesn't work. Now doesn't matter data retrieved, also if don't come back nothing is good. The important is to open the position. How you programm the second version on this code?
Please read the documentation on WebRequest. There is an example of coding both versions, so look at the 2nd example.
/
To add comments, please log in or register