esp_http_client: how to post using json?

imovit
Posts: 8
Joined: Sun Jul 29, 2018 1:52 pm

esp_http_client: how to post using json?

Postby imovit » Mon Jul 30, 2018 11:08 pm

Hi
I can issue a post action with success but body arrives to rest server as text and then is not well interpreted. I need to send body as json. I did


...
const char *post_data = "{\"channel\":\"A\",\"value\":\"X\"}";
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_post_field(client, post_data, strlen(post_data));
//esp_http_client_set_header(client, "Content-Type", "application/json");
esp_err_t err = esp_http_client_perform(client);
...

This works but post_data is sent as text. If I use

...
const char *post_data = "{\"channel\":\"A\",\"value\":\"X\"}";
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_post_field(client, post_data, strlen(post_data));
esp_http_client_set_header(client, "Content-Type", "application/json");
esp_err_t err = esp_http_client_perform(client);
...

I see:

Guru Meditation Error: Core 0 panic'ed (LoadProhibited)
. Exception was unhandled.


Why?

In my mind it seems that a a json parser is missing?! I dont know... post_data is already json... Do I need a json parser. If so, I dont hvae any idea how to configure it.

Help please...

chegewara
Posts: 815
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp_http_client: how to post using json?

Postby chegewara » Tue Jul 31, 2018 11:32 am

Could you use make monitor and paste full backtace?

imovit
Posts: 8
Joined: Sun Jul 29, 2018 1:52 pm

Re: esp_http_client: how to post using json?

Postby imovit » Tue Jul 31, 2018 12:44 pm

Finally "done"...
I was creating a destroying all the rest things per request. o, the first run well but the other ones do not .
Now, recycling all the things and changing only the post data, it works...
Thanks a lot

Who is online

Users browsing this forum: Baidu [Spider] and 27 guests