2

I have a program running on an esp8266 that attempts to fetch json data from an HTTPS endpoint that is hosted on aws amplify (data comes from a next.js app).

I can retrieve the data correctly when I use WifiClient alone, but when I want to use HttpClient, I get this error:

[HTTP] GET... failed, error: connection failed

This is my code:

void Network::get_data()
{
    if (consumption_data)
        return;
const char *endpoint = "https://.....";

wifi_client.setInsecure();
http_client.setTimeout(10000);

if (!http_client.begin(wifi_client, endpoint))
{
    Serial.println("Connection failed");
}

// Make the HTTP request
String payload;
int http_code = http_client.GET();

if (http_code == HTTP_CODE_OK)
{
    payload = http_client.getString();
}

else
{
    Serial.printf("[HTTP] GET... failed, error: %s\n", http_client.errorToString(http_code).c_str());
    return;
}

Serial.print("Payload: ");
Serial.println(payload);

// Parse JSON response

}

My class contains these:

    WiFiClientSecure wifi_client;
    HTTPClient http_client;

The endpoint is accessible from postman and doesn't require any auth headers. Any idea what the problem may be?

Thank you

seddouguim
  • 121
  • 2

0 Answers0