WebRequest always returns a 5203 error

 

I am not able to make web request to an API using WebRequest from a script, I always get back an error 5203.

This is the code, that I think is as simple as it can get. I am using MT4 build 765.

#property copyright "just a test"
#property link      ""
#property version   "1.00"
#property strict

void OnStart() {
    const string api_url = "https://example.org/service/call";
    const string cookie = NULL;
    const string referer = NULL;
    const int timeout = 5000;

    char data[], result[];
    int data_size;
    string result_headers;

    string msg = StringConcatenate(
        "symbol=", Symbol(),
        "&reason=", "moving",
        "&time=22:44:12", "%20", "Apr", "%20", 16
    );

    Print("msg: ", msg);
    StringToCharArray(msg, data, 0, WHOLE_ARRAY, CP_UTF8);
    data_size = ArraySize(data);

    int res;
    res = WebRequest("GET", api_url, cookie, referer, timeout, data, data_size, result, result_headers);

    Print("Status code: " , res, ", error: ", GetLastError());
    Print("Server response: ", CharArrayToString(result));
}


I have already added the api_url to the list of allowed URLs in the configuration.


Can anyone spot where is the error?

 
ale: Can anyone spot where is the error?
Does https://example.org/service/call exist?
 
WHRoeder:
ale: Can anyone spot where is the error?
Does https://example.org/service/call exist?

Sure it does, but it is a private service and I cannot write its address online.

I am sure that the service works and I can reach it from the same workstation in which MT4 is running.

MT4 is not making any request at all: I know because I see no requests from my workstation in the logs of the remote service.

 

I have found what is causing this issue: WebRequest has problems with the HTTPS certificate used by service. Using the HTTP version works.


Now the problem is that the query string is not sent using the data mechanism. I changed the code to

    int data_size = 0;

    res = WebRequest("GET", api_url + "?" + msg, cookie, referer, timeout, data, data_size, result, result_headers);
 
ale:

I have found what is causing this issue: WebRequest has problems with the HTTPS certificate used by service. Using the HTTP version works.


Now the problem is that the query string is not sent using the data mechanism. I changed the code to


Hi, my friend. To use data parameter you have to set method to "POST". I have been test it right now using MT5.

Reason: