Send JSON using AT+HTTPCLIENT

klteng
Posts: 10
Joined: Sat Feb 25, 2017 4:15 pm

Send JSON using AT+HTTPCLIENT

Postby klteng » Mon Oct 11, 2021 10:07 am

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.

ESP_Alson
Posts: 106
Joined: Mon Mar 22, 2021 3:37 am

Re: Send JSON using AT+HTTPCLIENT

Postby ESP_Alson » Thu Dec 30, 2021 7:11 am


JerryFrag
Posts: 6
Joined: Mon May 09, 2022 8:20 pm

Re: Send JSON using AT+HTTPCLIENT

Postby JerryFrag » Mon May 09, 2022 8:38 pm

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.

ESP_Sun
Posts: 326
Joined: Thu Dec 30, 2021 9:52 am

Re: Send JSON using AT+HTTPCLIENT

Postby ESP_Sun » Tue May 10, 2022 11:11 am

It seems that the special characters you are using are not all escaped.
企业微信截图_16521809705869.png
企业微信截图_16521809705869.png (22.42 KiB) Viewed 8009 times

JerryFrag
Posts: 6
Joined: Mon May 09, 2022 8:20 pm

Re: Send JSON using AT+HTTPCLIENT

Postby JerryFrag » Tue May 10, 2022 1:42 pm

Thank you very much.

This solved my problem (escaping the comma \, in the JSON string)!

Who is online

Users browsing this forum: No registered users and 13 guests