Send JSON using AT+HTTPCLIENT
Send JSON using AT+HTTPCLIENT
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
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.
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
It seems that the special characters you are using are not all escaped.
Re: Send JSON using AT+HTTPCLIENT
Thank you very much.
This solved my problem (escaping the comma \, in the JSON string)!
This solved my problem (escaping the comma \, in the JSON string)!
Who is online
Users browsing this forum: No registered users and 29 guests