I'm using esp32 wroom kit to get familiar with the http protocol, try to use the POST request to send values to a server running on ubuntu machine. I'm able to connect to wifi router and using this code:
Code: Select all
esp_http_client_config_t config_post = {
.url = "http://192.168.0.4/index.php",
.method = HTTP_METHOD_POST,
.cert_pem = NULL,
.event_handler = client_event_post_handler};
esp_http_client_handle_t client = esp_http_client_init(&config_post);
const char *post_data = "from esp32";
esp_http_client_set_method(client,HTTP_METHOD_POST);
esp_http_client_set_header(client, "Content-Type", "application/json");
esp_http_client_set_post_field(client, post_data, strlen(post_data));
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %"PRId64,
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
}
esp_http_client_cleanup(client);
Code: Select all
HTTP_EVENT_ON_DATA:
<html>
<body>
</body>
</html>
I already test the php script with a little curl code and the php script is working.
Maybe I missed something in the config for the client but, shouldn't the POST request sent the array data? I don't understan why the php works with curl code and NOT with the POST request from the esp32.
I also tried with "/post" at the end of the url of the server but that didn't work either.
Regards
Gastón