mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-07 22:54:33 +02:00
Fetch headers in POST example for native requests
In the POST section of `http_native_request` headers are not fetched. thus, just commenting out the GET request example would result in a `status` and `content_length` of `0` being reported (quite confusing). (Plus, it should log `HTTP POST Status` here, instead of `HTTP GET Status`.) Merges https://github.com/espressif/esp-idf/pull/7696
This commit is contained in:
@@ -624,9 +624,13 @@ static void http_native_request(void)
|
||||
if (wlen < 0) {
|
||||
ESP_LOGE(TAG, "Write failed");
|
||||
}
|
||||
content_length = esp_http_client_fetch_headers(client);
|
||||
if (content_length < 0) {
|
||||
ESP_LOGE(TAG, "HTTP client fetch headers failed");
|
||||
} else {
|
||||
int data_read = esp_http_client_read_response(client, output_buffer, MAX_HTTP_OUTPUT_BUFFER);
|
||||
if (data_read >= 0) {
|
||||
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
|
||||
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d",
|
||||
esp_http_client_get_status_code(client),
|
||||
esp_http_client_get_content_length(client));
|
||||
ESP_LOG_BUFFER_HEX(TAG, output_buffer, strlen(output_buffer));
|
||||
@@ -634,6 +638,7 @@ static void http_native_request(void)
|
||||
ESP_LOGE(TAG, "Failed to read response");
|
||||
}
|
||||
}
|
||||
}
|
||||
esp_http_client_cleanup(client);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user