"Send header failed" in GET request for M5Stack as Https client


I am trying to develop a weather app on the M5Stack using the Arduino IDE. I am using the M5Stack-Core-ESP32. The code I am using is attached in this post and my goal is ultimately to manage to get the information that is displayed in the url “https://api.openweathermap.org/data/2.5/forecast?q=torino,IT&cnt=3&appid=9679ff43a5719aaef0a19dcf10607229” on to the monitor of the M5Stack. My code is based on this code:
Running my code I get the following messages on the M5Stack:
Starting conn to server…
connected to server
[HTTPS] begin…
[HTTPS] GET …code: -2
[HTTPS] GET …failed, error: send header failed

(and so on, the messages repeat themselves because they are in the loop())

As you can see, the value of the httpCode after the connection to the server is “-2”. This is why the code doesn’t manage to enter the if-clause at line 63. According to the HttpClient.h file (which you can find here: HttpClient/HttpClient.h at master · amcewen/HttpClient · GitHub), a value of -2 for the HTTP_ERROR_API constant means that " This call was made when the HttpClient class wasn’t expecting it to be called. Usually indicates your code is using the class incorrectly". Furthermore, the error message displayed on the M5Stack monitor according to the instructions in the code is “send header failed”.

I am having a hard time understanding these error messages and hints. What does it mean that “the HttpClient class wasn’t expecting it to be called”? And I don’t know how to solve this problem so as to not get the error message again and enter the if clause at line 63.

Any help would be greatly appreciated.

Also a more general question: is the code I am using, bug aside, good for achieving my goal of getting the weather information on the M5Stack?

Thanks a lot in advance :slight_smile:

Pressy.ino (3.92 KB)