How to send a POST with a JSON in a WebRequest() call using MQL4?

前端 未结 4 1295
旧时难觅i
旧时难觅i 2020-12-16 23:52

I would like to send a POST from MQL4-script, using a JSON-format to a Node-server.

I\'ve tried the webReque

4条回答
  •  独厮守ぢ
    2020-12-17 00:31

    It works well for me, I have someone like this :

    string response = SendResquest("POST", "GetPrediction", "[4, 7]", "Content-Type: application/json", 5000);
    
    string SendResquest(string httpType, string methodName, string bodyData = "", string headers = "", int timeout)
    {
        uchar bodyDataCharArray[];
        ArrayResize(bodyDataCharArray, StringToCharArray(bodyData, bodyDataCharArray)-1);
    
        int response = WebRequest(httpType, this.address+methodName, headers, timeout, bodyDataCharArray, this.resultDataCharArray, this.resultHeader);
    
        string result = CharArrayToString(this.resultDataCharArray); 
    
        if(response == 200)
            return result;
        Print("Error when trying to call API : ", response);
        return "";
    }
    

提交回复
热议问题