Page 1 of 1

esp_http_client returns error (cant connect)

Posted: Tue Dec 29, 2020 4:32 pm
by janav1
I am trying to use esp_http_client with ESP8266 RTOS SDK v3.3 to perform HTTP POST using TLS, but the library fails with error:

Code: Select all

<ESC>[0;31mE (127251) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x4c<ESC>[0m<CR><LF>
<ESC>[0;31mE (127255) esp-tls: Failed to open new connection<ESC>[0m<CR><LF>
<ESC>[0;31mE (127258) TRANS_SSL: Failed to open a new connection<ESC>[0m<CR><LF>
<ESC>[0;31mE (127269) HTTP_CLIENT: Connection failed, sock < 0<ESC>[0m<CR><LF>
<ESC>[0;31mE (127274) HTTPS: Error perform http request ESP_ERR_HTTP_CONNECT<ESC>[0m<CR><LF>

code to reproduce the error (_http_event_handler is the default one provided in examples):

Code: Select all

esp_http_client_config_t config = {
            .host = "",
            .path = "/a/check",
            .transport_type = HTTP_TRANSPORT_OVER_SSL,
            .event_handler = _http_event_handler,
      esp_http_client_handle_t client = esp_http_client_init(&config);
      esp_err_t err = esp_http_client_perform(client);
      if (err == ESP_OK) {
         int sc = esp_http_client_get_status_code(client);
         ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d", sc, esp_http_client_get_content_length(client));
         if(sc == 200){
            esp_http_client_read_response(client, post_data, 512);
      } else {
         ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));

Has anyone encountered the same problem? How to solve it?

Edit 1: Since no one has responded yet, should I assume that the http_client library works for everyone?

Re: esp_http_client returns error (cant connect)

Posted: Thu Apr 22, 2021 5:58 pm
by Her Mary
The latest RTOS 3.4 is released recently, maybe you could have a try to see if the issue persists?

Re: esp_http_client returns error (cant connect)

Posted: Fri Apr 23, 2021 3:09 pm
by janav1
Thank you for your response. I am using the latest version (v3.4) and I figured out, that the issue is with TLS component, enabling TLS in MQTTClient causes same issue.
As I am not providing the certificate in the config (because I dont need to verify the server), the connection fails. This should be solved by setting "CONFIG_ESP_TLS_INSECURE" in the MENUCONFIG, but this option is missing (see attachment).