🛠 Récupérer une page web en HTTP simple

Arduino MKR WiFi 1010 · intermediaire · Schéma : IMG-mkr-wifi-1010-intermediaire-2-mkrwifi-http-get.svg — Requête HTTP GET émise par la MKR WiFi 1010 connectée en station vers un serveur distant sur le port 80, réponse affichée dans le moniteur série.

Objectives

Following the station connection from the previous tutorial, establish a raw TCP socket on port 80 using WiFiClient and manually write an HTTP/1.1 request (GET, Host header, Connection: close), then read the response byte by byte. This helps you understand what a "high-level" HTTP library does for you — and why HTTPS comes next.

Hardware

Complete Code

#include <WiFiNINA.h>

const char* SSID = "votre-ssid";
const char* PASS = "votre-mot-de-passe";
WiFiClient client;   // TCP simple (WiFiSSLClient pour TLS)

void setup {
  Serial.begin(115200);
  WiFi.begin(SSID, PASS);
  while (WiFi.status != WL_CONNECTED) { delay(500); Serial.print("."); }
  Serial.printf("\nIP: %s\n", WiFi.localIP.toString.c_str);

  if (client.connect("example.com", 80)) {
    client.println("GET / HTTP/1.1");
    client.println("Host: example.com");
    client.println("Connection: close");
    client.println;                    // ligne vide = fin d'en-tetes
    while (client.available)
      Serial.write(client.read);
    client.stop;                       // libere la connexion
  } else {
    Serial.println("Connexion TCP refusee");
  }
}

void loop { delay(60000); }  // une seule requette suffit

Expected Verification

The serial monitor dumps the complete HTML of the page (response headers + body). client.stop must be called to release the module's socket; otherwise, subsequent connections may remain blocked. On a captive network (hotel, corporate), the TCP connection succeeds but returns the authentication page instead.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials