What can be the reason that the POST payload is not sent over the wire? I've used WireShark to do the network trace - no payload is sent, but I see the headers correctly and the data is properly received back from the server.
I'm using ESPIDF v5.1.5 - I can't update to the newer one due to heave backward compatibility limitations
- esp_err_t client_event_post_handler(esp_http_client_event_handle_t evt)
- {
- switch (evt->event_id)
- {
- case HTTP_EVENT_ON_DATA:
- ESP_LOGI("HANDLER", "HTTP_EVENT_ON_DATA: %.*s\n", evt->data_len, (char *)evt->data);
- break;
- default:
- break;
- }
- return ESP_OK;
- }
- std::string http_post(const std::string &url, const std::string &payload) {
- esp_http_client_config_t config_post = {
- .url = url.c_str(),
- .cert_pem = NULL,
- .method = HTTP_METHOD_POST,
- .event_handler = client_event_post_handler};
- esp_http_client_handle_t client = esp_http_client_init(&config_post);
- char *post_data = "{\"User\":\"User1\"}";
- esp_http_client_set_post_field(client, post_data, strlen(post_data));
- esp_http_client_set_header(client, "Content-Type", "application/json");
- esp_http_client_perform(client);
- esp_http_client_cleanup(client);
- ESP_LOGI(TAG, "Sent data");
- return "";
- }