Code: Select all
void https_basic_auth_task(void *pvParameter)
{
static const char *TASK_TAG = "POST_TASK";
// HTTP Config
esp_http_client_config_t config = {
.url = "https://protected.example.com/protect",
.event_handler = _http_event_handler,
.username = "user1",
.password = "pass123",
.auth_type = HTTP_AUTH_TYPE_BASIC,
};
// POST
esp_http_client_handle_t client = esp_http_client_init(&config);
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, json_buffer, strlen(json_buffer));
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TASK_TAG, "HTTP POST Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TASK_TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
}
vTaskDelete( NULL );
}
Code: Select all
E (35773) esp-tls: Failed to connect to host (errno 113)
E (35773) esp-tls: Failed to open new connection
E (35773) TRANS_SSL: Failed to open a new connection
E (35773) HTTP_CLIENT: Connection failed, sock < 0
E (35783) POST_TASK: HTTP POST request failed: ESP_ERR_HTTP_CONNECT
Code: Select all
E (29343) HTTP_CLIENT: Error, reach max_redirection_count count=10
E (29343) HTTP_CLIENT: Error response
E (29343) POST_TASK: HTTP POST request failed: ESP_ERR_HTTP_MAX_REDIRECT
Any clue what I am doing wrong?
I think there should be a basic auth + https example here:
https://github.com/espressif/esp-idf/bl ... _example.c