What Is HTTP
HTTP (HyperText Transfer Protocol) is the most widely used "request-response" protocol on the Internet: a client (your module, browser, or mobile app) sends a request, and the server returns a response. Web browsing, weather queries, and device data reporting mostly run over HTTP.
HTTP is a text protocol — requests and responses are human-readable text lines with a fixed format that is easy to debug. It is not encrypted by itself; when encryption is needed, use HTTPS (HTTP + TLS/SSL, see HTTPS page).
Request
An HTTP request consists of three parts:
Request line: method + space + URL + space + protocol version, for example:
GET /index.html HTTP/1.1Headers: one "key: value" per line, giving the server extra information, for example:
Host: www.gov.cn
User-Agent: Ai-M62
Content-Type: application/jsonBody: optional. GET usually has no body; POST/PUT use it to carry submitted data (forms, JSON, etc.).
Response
The server's response also consists of three parts:
Status line: protocol version + space + status code + space + reason phrase, for example:
HTTP/1.1 200 OKResponse headers: same format as request headers, e.g. Content-Type (content type) and Content-Length (content length).
Response body: the actual content returned by the server (HTML, JSON data, images, etc.).
Common Methods
| Method | Meaning | Typical use |
|---|---|---|
| GET | Retrieve a resource | Request a web page, query weather, read device state; parameters go in the URL |
| POST | Submit data | Create a resource: login, report data, publish a message; data goes in the body |
| PUT | Replace entirely | Replace a resource with the request body |
| DELETE | Remove a resource | Delete the specified resource on the server |
Corresponding tutorials: GET, POST, PUT, DELETE.
Common Status Codes
| Code | Meaning | Notes |
|---|---|---|
| 200 | OK | Request succeeded |
| 201 | Created | Creation succeeded (common with POST) |
| 301/302 | Redirect | The resource moved; the client should follow the redirect |
| 400 | Bad Request | Malformed request |
| 401 | Unauthorized | Not authenticated |
| 403 | Forbidden | No permission |
| 404 | Not Found | Resource does not exist |
| 500 | Internal Server Error | Server-side error |
Relationship with the SDK Example
The Bouffalo SDK example examples/wifi/sta/wifi_http demonstrates issuing HTTP requests from the module: flash the firmware, connect to Wi-Fi, then type wifi_http_test <url> in the serial shell. The example uses the https_client component to send the request and receives/prints the server response through a callback (response_cb).
- Internally the example resolves the hostname to an IP (
gethostbyname), opens a TCP connection (port 80), sends the HTTP text, and receives the response via callbacks; - The four method pages (GET/POST/PUT/DELETE) are all based on this example; the full code and API explanations are on each page;
- HTTPS (encrypted HTTP) is covered in the HTTPS page, backed by the SDK example
examples/wifi/sta/wifi_https.
Summary
- HTTP is a text request-response protocol: the client sends "method + URL + headers + body", the server replies with "status code + headers + body";
- GET retrieves data, POST submits data, PUT replaces entirely, DELETE removes;
- Status codes: 2xx success, 3xx redirect, 4xx client error, 5xx server error;
- Before running HTTP on the module, make sure it is connected to Wi-Fi (
wifi_sta_connect <ssid> <password>).
Have questions?
For any other questions, visit the unified Q&A and discussion board: Ai-Thinker Discussions

