ESP32 - HTTP Request
This tutorial instructs you how to use ESP32 to make HTTP request to web server, API, or Web service. In detail, You will learn:
- How to use ESP32 to make HTTP request (GET and POST)
- How to include the sensor's data into HTTP request
Hardware Used In This Tutorial
|1||×||ESP-WROOM-32 Dev Module|
|1||×||Micro USB Cable|
Basic Concepts of Web Client and Web Server
There are some basic concepts of web such as: web address (URL), hostname, pathname, query string, HTTP Request... You can learn detailed about them in HTTP tutorial
How to Make an HTTP Request
- Declare request method, HTTP port, hostname, pathname, query string
- Declare a web client object
- Connect to web server
- If connected to server, send HTTP request
- Read the response data from web server
How to include data into HTTP request
We can send data to the web server by including data into HTTP request. The data format depends on HTTP request method:
- For HTTP GET request
- Data can be only sent in query string on the pathname.
- HTTP POST request
- Data can be sent NOT ONLY in query string format BUT ALSO any other format such as Json, XML, image ...
- Data is put in HTTP request body.
Let's learn how to send data in query string format for both HTTP GET and POST
- Create a query string
- HTTP GET: add query string to pathname
- HTTP POST: put query string in HTTP body
- For both GET and POST, read the response data from web server
Complete ESP32 Code for Making HTTP Request
The blow is the complete ESP32 code for making HTTP GET/POST request
Complete ESP32 Code for Making HTTP GET Request with data
Complete ESP32 Code for Making HTTP POST Request with data
※ NOTE THAT:
Please note that this tutorial is under development. We will post on our Facebook Page when the tutorial is complete. Like it to get updated.