i has already check my server code by postman,it run sucessufully
here is my log
I (7427) example: HTTP_EVENT_ON_CONNECTED
I (7437) example: HTTP_EVENT_HEADER_SENT
E (7437) example: Failed to upload data: ERROR
I (7437) example: HTTP_EVENT_DISCONNECTED
and my code
- esp_http_client_config_t config = {
- .url = "http://192.168.206.200:3000/test",
- .event_handler = http_event_handler,
- .method = HTTP_METHOD_POST,
- .timeout_ms = 5000,
- .buffer_size = 1024,
- .user_data = NULL,
- .is_async = false,
- .use_global_ca_store = true,
- .disable_auto_redirect = false,
- .max_redirection_count = 10,
- .auth_type = HTTP_AUTH_TYPE_NONE,
- // .auth_cred = {
- // .username = NULL,
- // .password = NULL,
- // .digest = NULL,
- // },
- .query = NULL,
- // .header = {
- // .key = "Content-Type",
- // .value = "application/octet-stream",
- // },
- // .query_len = 0,
- // .header_len = 0,
- };
- esp_http_client_handle_t client = esp_http_client_init(&config);
- const char *data = "hello world!";
- int data_len = strlen(data);
- ESP_LOGI(TAG,"%d",data_len);
- char data_len_str[10];
- itoa(data_len, data_len_str, 10);
- esp_http_client_set_header(client, "Transfer-Encoding", "chunked");
- esp_http_client_set_header(client, "Content-Length","12");
- esp_http_client_set_header(client, "Content-Type", "application/octet-stream");
- esp_err_t err = esp_http_client_open(client, data_len);
- if (err != ESP_OK) {
- ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
- goto cleanup;
- }
- err = esp_http_client_write(client, data, data_len);
- if (err != ESP_OK) {
- ESP_LOGE(TAG, "Failed to upload data: %s", esp_err_to_name(err));
- goto cleanup;
- }
- err = esp_http_client_fetch_headers(client);
- if (err != ESP_OK) {
- ESP_LOGE(TAG, "Failed to fetch HTTP response headers: %s", esp_err_to_name(err));
- goto cleanup;
- }
- int status_code = esp_http_client_get_status_code(client);
- ESP_LOGI(TAG, "HTTP response status code: %d", status_code);
- cleanup:
- esp_http_client_cleanup(client);