NodeMCU ESP8266 HTTP GET request not working

Hello there!
I am trying to create a home weather station using the NodeMCU ESP8266 board. I am somewhat of a beginner, so I have had some trouble along the way. All the problems which I have encountered have been relatively easy to fix, until now.

Below is my code, where I establish a connection with the wifi, then make an HTTP.GET request on a weather API, then print the results. (I have changed my wifi info and API key)

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

HTTPClient http;
WiFiClient client;
const char* ssid = "ssid";
const char* password = "password";
void setup () {
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
void loop() {
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
    HTTPClient http;  //Declare an object of class HTTPClient
    http.begin(client, "");  //Specify request destination
    int httpCode = http.GET();                                  //Send the request
    if (httpCode > 0) { //Check the returning code
      String payload = http.getString();   //Get the request response payload
      Serial.println(payload);             //Print the response payload
    http.end();   //Close connection
  delay(30000);    //Send a request every 30 seconds

When I run the program, I receive a rather confusing error message:

C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp: In member function 'bool HTTPClient::begin(WiFiClient&, const String&)':
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp:88:22: **error: 'class WiFiClient' has no member named 'clone'**
**   88 |     _client = client.clone();**
**      |                      ^~~~~**
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp: In member function 'bool HTTPClient::begin(WiFiClient&, const String&, uint16_t, const String&, bool)':
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp:105:22: **error: 'class WiFiClient' has no member named 'clone'**
**  105 |     _client = client.clone();**
**      |                      ^~~~~**
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This definitely has something to do with the library 'ESP8266HTTPClient.h'. I had previously had some trouble with importing it to the sketch, but now there appears to be something wrong with the actual library. I need to figure out if its something wrong with my code, or if I need to find a new library. :upside_down_face:

Any help would be greatly appreciated, thanks!

Hi @beefserky,

I'm not sure what the problem is. I would probably just start with re-downloading the library. Library: Arduino/libraries/ESP8266HTTPClient at master · esp8266/Arduino · GitHub

Download that, and then take the file and place it in "Arduino/libraries". Make sure to delete the old one first. Then restart your IDE and try uploading the code again.

1 Like

you downloaded a development version of the ESP8266HTTPClient library and it doesn't match the rest of the esp8266 core

1 Like

Hey kgray! I tried deleting then redownloading the library into programfilesx86/Arduino/libraries, but I am getting the same error after restarting the ide. I don't know if this is standard, but to download the library I have to download the 'Arduino master' file under which the libraries are, then once the zip is downloaded I find the library I need and copy it into the Arduino files. This is because it won't let me download just the library for some reason. Also, the library text is green for some reason, I don't know why.

Hi Juraj, thanks for the reply. What do you mean by development? Should I revert the library back to an original version? BTW, when I call the library name, it appears green, instead of orange or black. does this mean something? Thanks in advance.

Oh, that's right. The ESP8266HTTPClient.h library is already built-in.

I just checked your first post and I think I figured out what happened. HTTPClient http; at the beginning of the loop can't be there. It will "clone" the instance over and over. Place this line right after the "#include" statements and before the setup.

1 Like

thanks so much for replying again! You are very kind. I tried what you said, but unfortunately, it didn't work. I think there is something wrong with this version of the library. I have, however, found a solution that uses a different library, and I have edited my code accordingly. It works! I can get live weather data into my serial monitor.

For anyone having trouble with this kind of thing I recommend watching this video:

1 Like

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