# Problem with HTTPS request on esp8266

**URL:** <https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546>\
**Category:** Programming\
**Created:** [June 19, 2023, 3:45pm UTC](https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546 "2023-06-19T15:45:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mseddougui](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mseddougui](https://forum.arduino.cc/u/mseddougui)\
**Post date:** [June 19, 2023, 3:45pm UTC](https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546/1 "2023-06-19T15:45:38Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [June 20, 2023, 3:42pm UTC](https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546/2 "2023-06-20T15:42:45Z")

</div>

> [@mseddougui](#):
>
> ```arduino
> HTTPClient http_client;
> 
> ```

Which exact library are you using? With that exact name I know only the library from the ESP32 core but you wrote you use an ESP8266. If you're using that library, did you check that you don't have to provide the root certificate for your site?

---

<div class="post-metadata">

**Author:** ![mseddougui](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mseddougui](https://forum.arduino.cc/u/mseddougui)\
**Post date:** [June 20, 2023, 4:05pm UTC](https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546/3 "2023-06-20T16:05:11Z")

</div>

Thank you for your reply.

I am using this library: `ESP8266HTTPClient.h`

I didn't provide the object with my site's root certificate but I thought that using the `setInsecure()` function on my wifi\_client meant that I didn't have to.

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [June 21, 2023, 4:30pm UTC](https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546/4 "2023-06-21T16:30:35Z")

</div>

> [@mseddougui](#):
>
> I didn't provide the object with my site's root certificate but I thought that using the `setInsecure()` function on my wifi\_client meant that I didn't have to.

You're right, I missed that line.

> [@mseddougui](#):
>
> I am using this library: `ESP8266HTTPClient.h`

The error you get is only returned if a connection to port 443 on the target host isn't possible. That either means you specified a wrong URL, have no WiFi connectivity or your WiFi network has no Internet connection.

Try the connectivity yourself: connect a PC to the same WiFi network and enter the following command:

`telnet <hostname of URL> 443`

where the string in \<\> has to be replaced by the hostname in the URL of your sketch.  
If that returns an error you have to fix your network.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 18, 2023, 4:30pm UTC](https://forum.arduino.cc/t/problem-with-https-request-on-esp8266/1139546/5 "2023-12-18T16:30:43Z")

</div>

Closed on December 18, 2023, 4:30pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
