Help with WebRequest POST generating invalid JSON body
Hi
I'm trying to post the below to my express js endpoint
I have a function below but it's posting an invalid JSON body to my express js.
Body
How do I correct this?
thanks
You should be using a JSON serializer.
#include <jason.mqh> void OnStart() { CJAVal json; json["key"] = "value"; Print(json.Serialize()); }
- www.mql5.com
You mean something like this? It's still show invalid body. Could you give me an example how I can do a POST on this?
void PostOrderStatusAPI(string pair, int order_type) { if(MQLInfoInteger(MQL_TESTER)) { } else { // JSON text to send // string strJsonText= "{\"key\"= \"value\"}; CJAVal json; json["key"] = "value"; // Text must be converted to a uchar array. Note that StringToCharArray() adds // a nul character to the end of the array unless the size/length parameter // is explicitly specified uchar jsonData[]; StringToCharArray(json.Serialize(), jsonData, 0, StringLen(json.Serialize()),CP_UTF8); // Use MT4's WebRequest() to send the JSON data to the server. char serverResult[]; string serverHeaders; int res = WebRequest("POST", "http://x.x.x.x/api/updatetradingstatus/", "", "", 10000, jsonData, ArraySize(jsonData), serverResult, serverHeaders); Print("Web request result: ", res, ", error: #", (res == -1 ? GetLastError() : 0)); } }
Dear nicholish en
would you please provide the code to de serialize this JSON URL?
i tried a lot but all with false results.
https://search.codal.ir/api/search/v2/q?&Audited=true&AuditorRef=-1&Category=-1&Childs=true&CompanyState=-1&CompanyType=-1&Consolidatable=true&IsNotAudited=false&Length=-1&LetterType=-1&Mains=true&NotAudited=true&NotConsolidatable=true&PageNumber=1&Publisher=false&TracingNo=-1&search=true
Hi
I'm trying to post the below to my express js endpoint
I have a function below but it's posting an invalid JSON body to my express js.
Body
{ '{"key": "value"}': '' }How do I correct this?
thanks