Webrequest() to Connect to custom REST API

 

Hello dev. I wanted to make a bot that interacts with an API i built . Only issue is that WebRequest keeps returning -1. Whet i run the same code in mt5 it is able to GET data from the API. I have googled and rummaged through other peoples code to no avail. I am guessing the issue is in the code of mt4 because of the response being -1. Meaning it was unable to send a request to my API . Please assist if you can figure out where am going wrong.

Here is the code. I have changed the headers multiple times to immitate browser headers and even left it as NULL but still no response




void OnTick()
  {
//---
   string headers;//= "Content-Type : application/json";
   string url= "http://127.0.0.1:5000 ";
   ResetLastError(); 
   char post[],result[];
   int response_code;
   string server_response_data;

   response_code=WebRequest("POST",url,NULL,NULL,5000,post,0,result,headers);
   server_response_data = CharArrayToString(result);
   Print(response_code); 
   
  }
//+------------------------------------------------------------------+

 

You may study the documentation.

Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://".

Documentation on MQL5: Network Functions / WebRequest
Documentation on MQL5: Network Functions / WebRequest
  • www.mql5.com
The function sends an HTTP request to a specified server. The function has two versions: 1. Sending simple requests of type "key=value...