HTTPClient Library
A simple HTTP requester that can handle both HTTP and HTTPS requests is
included as the HTTPClient
library.
Check the examples for use under HTTP and HTTPS configurations. In general, for HTTP connections (unsecured and very uncommon on the internet today) simply passing in a URL and performiung a GET is sufficient to transfer data.
// Error checking is left as an exercise for the reader...
HTTPClient http;
if (http.begin("http://my.server/url")) {
if (http.GET() > 0) {
String data = http.getString();
}
http.end();
}
For HTTPS connections, simply add the appropriate WiFiClientSecure calls
as needed (i.e. setInsecure()
, setTrustAnchor
, etc.). See the
WiFiClientSecure documentation for more details.
// Error checking is left as an exercise for the reader...
HTTPClient https;
https.setInsecure(); // Use certs, but do not check their authenticity
if (https.begin("https://my.secure.server/url")) {
if (https.GET() > 0) {
String data = https.getString();
}
https.end();
}
Unlike the ESP8266 and ESP32 HTTPClient
implementations it is not necessary
to create a WiFiClient
or WiFiClientSecure
to pass in to the HTTPClient
object.