Chapter 2. API Reference
* In case of string data, null termination will be absent, and
* content length would give length of string */
char
content[100];
/* Truncate if content length larger than the buffer */
size_t
recv_size
int
ret
=
httpd_req_recv(req, content, recv_size);
if
(ret
<=
/* Check if timeout occurred */
if
(ret
/* In case of timeout one can choose to retry calling
* httpd_req_recv(), but to keep it simple, here we
* respond with an HTTP 408 (Request Timeout) error */
httpd_resp_send_408(req);
}
/* In case of error, returning ESP_FAIL will
* ensure that the underlying socket is closed */
return
}
/* Send a simple response */
const
char
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
return
ESP_OK;
}
/* URI handler structure for GET /uri */
httpd_uri_t uri_get
.uri
=
.method
=
.handler
=
.user_ctx
=
};
/* URI handler structure for POST /uri */
httpd_uri_t uri_post
.uri
=
.method
=
.handler
=
.user_ctx
=
};
/* Function for starting the webserver */
httpd_handle_t start_webserver(void)
{
/* Generate default configuration */
httpd_config_t config
/* Empty handle to esp_http_server */
httpd_handle_t server
/* Start the httpd server */
if
(httpd_start(&server, &config)
/* Register URI handlers */
httpd_register_uri_handler(server, &uri_get);
httpd_register_uri_handler(server, &uri_post);
}
/* If server failed to start, handle will be NULL */
return
server;
}
Espressif Systems
=
MIN(req->content_len, sizeof(content));
0) {
/* 0 return value indicates connection closed */
==
HTTPD_SOCK_ERR_TIMEOUT) {
ESP_FAIL;
resp[]
=
"URI POST
Response";
=
{
"/uri",
HTTP_GET,
get_handler,
NULL
=
{
"/uri",
HTTP_POST,
post_handler,
NULL
=
HTTPD_DEFAULT_CONFIG();
=
NULL;
Submit Document Feedback
==
ESP_OK) {
572
(continued from previous page)
(continues on next page)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?