Send JSON using AT+HTTPCLIENT
Posted: Mon Oct 11, 2021 10:07 am
by klteng
I am trying to use the AT+HTTPCLIENT to send JSON message. If anyone have an example of using AT+HTTPCLIENT to send JSON message, it will be great! Please share the example with me. Thanks.
Re: Send JSON using AT+HTTPCLIENT
Posted: Thu Dec 30, 2021 7:11 am
by ESP_Alson
Re: Send JSON using AT+HTTPCLIENT
Posted: Mon May 09, 2022 8:38 pm
by JerryFrag
Hi,
I'm having an issue with AT+HTTPCLIENT, but only regarding sending JSON data.
If my JSON data is in the format of {"item1": "data1", "item2": "data2"}, I make sure to to escape the " so that my data looks like this:
{\"item1\": \"data1"\, \"item2\", "\data2"}
So the format of my command is as such: (POSTing JSON data over TSL)
AT+HTTPCLIENT=3,1,"url",,,2,"{\"item1\": \"data1"\, \"item2\", "\data2"}", "Authorization: ******"
the ESP returns ERROR. This would imply that there is something wrong with the formatting.
So if I send the same string, the only change being the data as {"\item\"1:\"data1\} then the server asks me for item2. So the formatting of the command for 1 JSON data item is fine, but more than that and the ESP32 doesn't like how the string is set up.
So there's something wrong with how my data string is set up, but after countless tries I can't seem to find an answer. Please advise if I'm doing something wrong.
-- So, one more thing I tried was using urlencoded data in this format
AT+HTTPCLIENT=3,0,"url",,,2,"item1=data1&item2=data2", "Authorization: ******"
and the data was POSTed properly.
I could really use some help solving the JSON problem.
Thank you.
Re: Send JSON using AT+HTTPCLIENT
Posted: Tue May 10, 2022 11:11 am
by ESP_Sun
It seems that the special characters you are using are not all escaped.
- 企业微信截图_16521809705869.png (22.42 KiB) Viewed 8034 times
Re: Send JSON using AT+HTTPCLIENT
Posted: Tue May 10, 2022 1:42 pm
by JerryFrag
Thank you very much.
This solved my problem (escaping the comma \, in the JSON string)!