EA result not returning correctly.

 

I have a public endpoint i want to hit with my EA

the endpoint is here:-

and if you hit it with the browser it returns 

{"current rate":"5.0"}

however, using the EA it returns this:- 

{"current rate":""}

like i say, i can use the browser, or even curl and it work but my MQL4 code doesn't

any ideas? 

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

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   // Define the URL of the API endpoint
   string url = "https://t6t1yeuvil.execute-api.us-east-1.amazonaws.com/prod/FRED";

   // Define the variables for storing the fetched data
   string response;

   // Prepare the necessary variables for WebRequest
   int timeout = 5000;
   string headers;
   uchar postData[];
   uchar responseData[];

   // Add the necessary settings for WebRequest
   string cookie = NULL;
   string referer = NULL;
   int maxSize = 1024 * 1024;
   
   // Fetch the data from the API endpoint
   int httpStatus = WebRequest("GET", url, cookie, referer, timeout, postData, maxSize, responseData, headers);
    Print(response);
   // Check if the request was successful
   if (httpStatus != -1)
   {
      response = CharArrayToString(responseData);
      Print("Data fetched successfully:");
      Print(response);
   }
   else
   {
      Print("Error fetching data. Error code:", GetLastError());
   }
}
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.05.08
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Danny Cooke:

I have a public endpoint i want to hit with my EA

the endpoint is here:-

and if you hit it with the browser it returns 

{"current rate":"5.0"}

however, using the EA it returns this:- 

{"current rate":""}

like i say, i can use the browser, or even curl and it work but my MQL4 code doesn't

any ideas? 

You should use the other WebRequest variant.

Then print the headers of the response.

What is the httpStatus value ?