yahboom
HomeTutorialsProduct
Solution
Blog
Online Store
About Us
EN/中文
Store
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

8. HTTP Client Experiment

HTTP Client


HTTP Client1. HTTP Client Overview2. Core Concepts2.1 HTTPClient Request Flow2.2 HTTP Status Codes3. Hardware Dependencies4. Project Architecture and Flow5. Code Analysis5.1 Configuration and Global Variables5.2 Send GET Request and Parse Response6. Operation Process6.1 Build and Flash6.2 Operation Steps6.3 Verification Methods7. FAQ


1. HTTP Client Overview

HTTP (HyperText Transfer Protocol) is the most widely used application layer protocol on the Internet. It is based on TCP and uses a request-response model: the client sends a GET request, and the server returns a status code + data. This experiment uses the HTTPClient library to send a GET request to example.com, parsing the HTTP status code and response body. From URL parsing, DNS lookup to TCP connection, sending request, and reading response, all are encapsulated by the library, done with just a few lines of code.

Typical Application Scenarios:

Application TypeExample
Calling REST APIGet weather, query database
Data ReportingSensor data uploaded to cloud platform via HTTP POST
Firmware DownloadOTA downloads .bin firmware from server
Web ScrapingCrawl simple JSON information

2. Core Concepts

2.1 HTTPClient Request Flow

For a single HTTP GET request, the HTTPClient library automatically completes 4 stages:

http.begin(url)        establish connection
   ↓    URL parsing → DNS resolution → TCP three-way handshake (blocking)
http.GET()             send request
   ↓    construct HTTP request line + headers → send → wait for response
   ↓    return HTTP status code (int), positive = success, negative = network error
http.getString()       read response body
   ↓    read response body into String (small data) or getStream() streaming read (large data)
http.end()             close connection
        TCP four-way handshake, release socket, must be called
MethodFunctionBlocking?
http.begin(url)URL parsing + DNS + TCP connectionYes
http.GET()Send GET request, return status codeYes (wait for response)
http.POST(data)Send POST request with form bodyYes (wait for response)
http.addHeader(key, val)Add custom request header before GET/POSTNo
http.getString()Read full response body as StringYes
http.getStream()Get streaming response body (large file/JSON stream)No (streaming read)
http.end()Close TCP connection, release resourcesNo

2.2 HTTP Status Codes

Return value logic for http.GET():

xxxxxxxxxx
> 0    HTTP status code (200/404/500, etc.), request reached server
= 0    No valid HTTP response received
< 0    Network layer error (-1 = connection failed, -11 = timeout)
Status CodeMeaningHandling in This Experiment
200 OKRequest successfulPrint response body
301 Moved PermanentlyPermanent redirect—
404 Not FoundResource not found—
500 Internal Server ErrorServer internal error—
-1Connection failed (DNS failed/unreachable)Print error message
-11Request timeoutPrint error message

3. Hardware Dependencies

Pure software experiment. Must first connect to router via WIFI-STA and ensure internet access (example.com).


4. Project Architecture and Flow

xxxxxxxxxx
setup()
  ├─ connectWiFi()
  ├─ http.begin(URL)           // parse URL → DNS → TCP connection
  ├─ code = http.GET()         // send GET request
  ├─ if code == 200:
  │    └─ payload = http.getString()  // read response body
  └─ http.end()                // close TCP connection

5. Code Analysis

Complete source code: Source code → Arduino → 3.Network Communication → HTTP_Client → HTTP_Client.ino

5.1 Configuration and Global Variables

xxxxxxxxxx
#include <HTTPClient.h>
const char* GET_URL = "http://example.com/get";

5.2 Send GET Request and Parse Response

​x
void setup() {
  Serial.begin(115200);
  connectWiFi();

  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;

    // begin() internally: parse URL → DNS resolution → TCP connection
    http.begin(GET_URL);

    // GET() returns HTTP status code, negative = network error
    int httpCode = http.GET();

    if (httpCode > 0) {
      Serial.printf("HTTP Code: %d\n", httpCode);
      if (httpCode == HTTP_CODE_OK) {   // 200
        String payload = http.getString();
        Serial.printf("Response: %s\n", payload.c_str());
      }
    } else {
      Serial.printf("Request failed: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();   // close TCP connection, must be called
  }
}

http.begin(url) internally completes URL parsing + DNS resolution + TCP three-way handshake; http.end() sends FIN to close connection. For POST requests, use http.addHeader() to add headers and http.POST(data) to send form body.


6. Operation Process

6.1 Build and Flash

Arduino flashing process: See Arduino → 1. Before Development → 2. Build and Flash.

  1. Ensure router can access internet (example.com)

  2. Build and flash

6.2 Operation Steps

Step 1: Confirm Network Environment

Ensure the router connected to PC and ESP32 can access the internet. Open http://example.com in PC browser, should see the example webpage:

Website Page

Right-click page and select "View Page Source", can see the returned HTML content:

View Page Source

Client Source Code Page

Step 2: Build, Flash, and Open Serial Monitor

Build and flash the code to ESP32-S3 development board. Open serial monitor (baud rate 115200), wait for WiFi connection success.

Step 3: Observe HTTP Request Results

After ESP32 connects to WiFi, it automatically sends a GET request to http://example.com/. Serial monitor prints HTTP status code and HTML response from server:

xxxxxxxxxx
HTTP Code: 200
Response: <!doctype html><html>...

Serial Monitor Output

  • HTTP Code: 200 means request successful

  • Response prints the complete HTML page source returned by example.com

Step 4: Verify Error Handling

Disconnect router from internet (unplug WAN cable, keep LAN WiFi normal), press RST to restart ESP32. At this point DNS resolution or TCP connection fails, GET() returns negative error code, serial prints error message like Request failed: connection refused.

6.3 Verification Methods

OperationExpected Result
Normal internetHTTP 200, print JSON response
Disconnect cablebegin() fails or GET() returns negative

7. FAQ

PhenomenonCauseSolution
GET() returns -1DNS failed or target unreachableCheck if you can ping example.com
getString() is emptyResponse body too large or Content-Length=0Use getStream() for large files streaming
Garbled ChineseTerminal encoding mismatchUse UTF-8 terminal
TCP Server Experiment
HTTP Server Experiment

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文