diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 65ec5fcb47..ae304c408a 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -721,6 +721,9 @@ esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client) static esp_err_t esp_http_check_response(esp_http_client_handle_t client) { + if (client->response->status_code >= HttpStatus_Ok && client->response->status_code < HttpStatus_MultipleChoices) { + return ESP_OK; + } if (client->redirect_counter >= client->max_redirection_count || client->disable_auto_redirect) { ESP_LOGE(TAG, "Error, reach max_redirection_count count=%d", client->redirect_counter); return ESP_ERR_HTTP_MAX_REDIRECT; diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index 3304cfd73f..8fae84b0f0 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -136,7 +136,11 @@ typedef struct { * Enum for the HTTP status codes. */ typedef enum { + /* 2xx - Success */ + HttpStatus_Ok = 200, + /* 3xx - Redirection */ + HttpStatus_MultipleChoices = 300, HttpStatus_MovedPermanently = 301, HttpStatus_Found = 302, HttpStatus_TemporaryRedirect = 307, diff --git a/examples/protocols/esp_http_client/main/esp_http_client_example.c b/examples/protocols/esp_http_client/main/esp_http_client_example.c index 9c7fb68c95..1932320198 100644 --- a/examples/protocols/esp_http_client/main/esp_http_client_example.c +++ b/examples/protocols/esp_http_client/main/esp_http_client_example.c @@ -124,6 +124,7 @@ static void http_rest_with_url(void) .query = "esp", .event_handler = _http_event_handler, .user_data = local_response_buffer, // Pass address of local buffer to get response + .disable_auto_redirect = true, }; esp_http_client_handle_t client = esp_http_client_init(&config);