0% found this document useful (0 votes)
3 views1 page

Function HTTP Get

The document outlines a function for making an HTTP GET request using the ESP8266 microcontroller. It initializes a WiFi client and an HTTPClient object, constructs a request to a specified URL, and handles the response by printing the HTTP response code and content. If an error occurs, it prints an error message along with the response code before closing the connection.

Uploaded by

Song Thi Mai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Function HTTP Get

The document outlines a function for making an HTTP GET request using the ESP8266 microcontroller. It initializes a WiFi client and an HTTPClient object, constructs a request to a specified URL, and handles the response by printing the HTTP response code and content. If an error occurs, it prints an error message along with the response code before closing the connection.

Uploaded by

Song Thi Mai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

void get_request_http(){

String URL= "//noi dung URL cac em tu tao theo dung cu phap cua trang web va theo
cac thong so ma ca em muon//"
Serial.println("Ok! ESP8266 perform http request");
// Initialize the client library
WiFiClient client; // Creates a client that can connect to to a specified
internet IP address and port as defined in client.connect()
HTTPClient http; //Declare an object of class HTTPClient
http.begin(URL);
// Your IP address with path or Domain name with URL path: http.begin(client,
serverName); // (Mot so version of ESP8266 can su dung lop client trong http.begin)
int http_respond_code=http.GET();
String Stringcode="{}";
if (http_respond_code >0){ // check the return code from OpenWeather
Serial.println(URL);
Serial.println("http_respond_code:");
Serial.println(http_respond_code);
Stringcode=http.getString();
Serial.println(Stringcode);
}
else {
Serial.println("Error Code");
Serial.println(http_respond_code);
}
http.end(); //Close connection

}
}

You might also like