Chapter 4. Software framework
4.5.2 HTTP
Does ESP8266 support HTTP hosting?
Yes, it does. ESP8266 can run as a server in both SoftAP and Station modes.
• When running as a server in SoftAP mode, clients can directly access the ESP8266 host or server
at 192.168.4.1 (default) IP address.
• When the server is accessed via a router, the IP address should be the one allocated to the ESP8266
by the router.
• When using SDK to write native code, please refer to relevant examples.
• When using AT commands, start a server using AT+CIPSERVER command.
How to use esp_http_client to send chunked data?
• Please use
HTTP Stream
to -1.
Then the "Transfer-Encoding"will be set to "chunked"automatically,please see
http_client_prepare_first_line() in esp_http_client.c.
• The code snippet is listed below for your reference:
static
void
http_post_chunked_data()
{
esp_http_client_config_t config
.url
=
"http://httpbin.org/post",
.method
=
HTTP_METHOD_POST,
force POST anyway
→
};
char
buffer[MAX_HTTP_OUTPUT_BUFFER]
esp_http_client_handle_t client
esp_err_t err
header "Transfer-Encoding: chunked" and method to POST
→
if
(err
!=
ESP_OK) {
ESP_LOGE(TAG,
return;
}
// Post some data
esp_http_client_write(client, "5", 1);
esp_http_client_write(client, "\r\n", 2);
esp_http_client_write(client, "Hello", 5);
esp_http_client_write(client, "\r\n", 2);
esp_http_client_write(client, "7", 1);
esp_http_client_write(client, "\r\n", 2);
esp_http_client_write(client,
esp_http_client_write(client, "\r\n", 2);
esp_http_client_write(client, "0", 1);
esp_http_client_write(client, "\r\n", 2);
esp_http_client_write(client, "\r\n", 2);
// After the POST is complete, you can examine the response as
using:
→
int
content_length
Espressif Systems
by setting the write_len parameter of esp_http_client_open()
// This is NOT required. write_len < 0
=
=
esp_http_client_open(client, -1);
"Failed to open HTTP connection:
"
World!", 7);
=
esp_http_client_fetch_headers(client);
Submit Document Feedback
=
{
=
{0};
esp_http_client_init(&config);
// write_len=-1
%s", esp_err_to_name(err));
// length
// data
// length
// data
// end
91
will␣
sets␣
required␣
(continues on next page)
Release master
Need help?
Do you have a question about the ESP and is the answer not in the manual?