please edit your post -
------------------
When you post code please use the CODE button (Alt-S)!
Place the cursor on WebRequest and press F1. Then use the example and replace it step by step with your code.
Try to remove that comma in your json request.
Change
\"%s\",}
\"%s\"}
The problem you are encountering happens when your string is converted into a char array.
In MQL5, strings are automatically terminated with the character '\0' (null character).
If you now convert the entire string into a char array, the last character of your char array is not "}" but '\0' . This results in an invalid JSON when sent to Discord.
This can be verified with the following debug output in your example script:
Alternatively, you can check whether the last character of the array is '\0' and remove it if necessary:
I hope I could help and wish you happy holidays! 😊
In MQL5, strings are automatically terminated with the character '\0' (null character).
If you now convert the entire string into a char array, the last character of your char array is not "}" but '\0' . This results in an invalid JSON when sent to Discord.
This can be verified with the following debug output in your example script:
// For debugging: print the JSON payload char by char for(int i = 0; i < ArraySize(postData); i++){ Print("postData[", i, "] = ", postData[i], " (", CharToString(postData[i]), ")"); }
** * ** ** **
KK 0 12:17:17.955 Test (BTCUSD,M1) postData[23] = 111 (o)
DS 0 12:17:17.955 Test (BTCUSD,M1) postData[24] = 114 (r)
LJ 0 12:17:17.955 Test (BTCUSD,M1) postData[25] = 100 (d)
GJ 0 12:17:17.955 Test (BTCUSD,M1) postData[26] = 34 (")
RM 0 12:17:17.955 Test (BTCUSD,M1) postData[27] = 125 (})
DJ 0 12:17:17.955 Test (BTCUSD,M1) postData[28] = 0 ()
So, you can either limit the length of the string:
StringToCharArray(jsonPayload, postData, 0, StringLen(jsonPayload));
// If last char is \0, remove it if(postData[ArraySize(postData) - 1] == 0){ ArrayResize(postData, ArraySize(postData) - 1); }I tested your script with both approaches, and both methods work as expected.
I hope I could help and wish you happy holidays! 😊
Lukas Roth #:
The problem you are encountering happens when your string is converted into a char array.
In MQL5, strings are automatically terminated with the character '\0' (null character).
If you now convert the entire string into a char array, the last character of your char array is not "}" but '\0' . This results in an invalid JSON when sent to Discord.
This can be verified with the following debug output in your example script:
Alternatively, you can check whether the last character of the array is '\0' and remove it if necessary:
I tested your script with both approaches, and both methods work as expected.
I hope I could help and wish you happy holidays! 😊
Thank you so much! It is executable. I successfully sent the message in English. Bless you! 😊
The problem you are encountering happens when your string is converted into a char array.
In MQL5, strings are automatically terminated with the character '\0' (null character).
If you now convert the entire string into a char array, the last character of your char array is not "}" but '\0' . This results in an invalid JSON when sent to Discord.
This can be verified with the following debug output in your example script:
** * ** ** **
KK 0 12:17:17.955 Test (BTCUSD,M1) postData[23] = 111 (o)
DS 0 12:17:17.955 Test (BTCUSD,M1) postData[24] = 114 (r)
LJ 0 12:17:17.955 Test (BTCUSD,M1) postData[25] = 100 (d)
GJ 0 12:17:17.955 Test (BTCUSD,M1) postData[26] = 34 (")
RM 0 12:17:17.955 Test (BTCUSD,M1) postData[27] = 125 (})
DJ 0 12:17:17.955 Test (BTCUSD,M1) postData[28] = 0 ()
So, you can either limit the length of the string:
I tested your script with both approaches, and both methods work as expected.
I hope I could help and wish you happy holidays! 😊

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The error message is that The request body contains invalid JSON.", "code":50109. I don't know how to correct the problem. Can anyone help me? Thanks!