HTTPS_BASIC_AUTH

uberthoth
Posts: 6
Joined: Tue Jun 11, 2019 4:06 am

HTTPS_BASIC_AUTH

Postby uberthoth » Mon Jul 01, 2019 2:01 am

When attempting to use basic auth in combination with https:

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 );
}
I get failures such as this:

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
or sometimes this:

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
If I turn off the basic auth on the server side of things this works instantly, turn it on, I get the failures above. Using http, everything works fine.

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

Who is online

Users browsing this forum: No registered users and 75 guests