Skip to content

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:

text
GET /index.html HTTP/1.1

Headers: one "key: value" per line, giving the server extra information, for example:

text
Host: www.gov.cn
User-Agent: Ai-M62
Content-Type: application/json

Body: 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:

text
HTTP/1.1 200 OK

Response 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

MethodMeaningTypical use
GETRetrieve a resourceRequest a web page, query weather, read device state; parameters go in the URL
POSTSubmit dataCreate a resource: login, report data, publish a message; data goes in the body
PUTReplace entirelyReplace a resource with the request body
DELETERemove a resourceDelete the specified resource on the server

Corresponding tutorials: GET, POST, PUT, DELETE.

Common Status Codes

CodeMeaningNotes
200OKRequest succeeded
201CreatedCreation succeeded (common with POST)
301/302RedirectThe resource moved; the client should follow the redirect
400Bad RequestMalformed request
401UnauthorizedNot authenticated
403ForbiddenNo permission
404Not FoundResource does not exist
500Internal Server ErrorServer-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

Released under the MIT License. Build Time 2026-09-11 14:52:23