Download MetaTrader 5
To add comments, please log in or register
Download MetaTrader 5 for iPad and trade anywhere!
ale
68
ale 2015.04.16 21:31 

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?

whroeder1
13610
whroeder1 2015.04.17 13:01  
ale: Can anyone spot where is the error?
Does https://example.org/service/call exist?
ale
68
ale 2015.04.17 14:01  
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.

ale
68
ale 2015.04.17 22:58  

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);
/
To add comments, please log in or register