What's new

Help Compilation error: 'http' was not declared in this scope

Status
Not open for further replies.

Alieson09

Forum Expert
Joined
Aug 30, 2021
Posts
2,246
Solutions
27
Reaction
2,961
Points
2,085
C++:
if (client.connected()){
    Serial.println("Connected in Loop");
    
    int httpCode;
    id = "";
    Serial.println("----------------GetID");
    http.beginRequest("http://localhost/arduinotest/test.php");
    http.sendHeader("Content-Type", "application/text");
    id = http.get();
    Serial.println(id);
    http.endRequest();
 
The error message "Compilation error: 'http' was not declared in this scope" suggests that the compiler is unable to recognize the "http" object that is being used in the code. This can happen if the necessary library has not been included or if there is a typo in the code.

To fix this issue, ensure that you have included the HTTPClient library in your code by adding the following line at the beginning of your file:

C++:
#include <HTTPClient.h>

If you have already included the library and are still encountering the error, double-check the spelling of the "http" object. It should be spelled exactly as "HTTPClient http;" if you have declared it as an object in your code.

Additionally, make sure that the HTTPClient library has been installed in your Arduino IDE. You can do this by going to the "Sketch" menu, selecting "Include Library", and then checking if "HTTPClient" appears in the list of installed libraries.

Once you have resolved the error, try compiling and uploading the code again. This should allow the code to run without any issues.
 
Status
Not open for further replies.

Similar threads

Back
Top