Chapter 2. API Reference
Get the value string of a field from the request headers.
Note
• This API is supposed to be called only from the context of a URI handler where httpd_req_t* request
pointer is valid.
• Once httpd_resp_send() API is called all request headers are purged, so request headers need be
copied into separate buffers if they are required later.
• If output size is greater than input, then the value is truncated, accompanied by truncation error as
return value.
• Use httpd_req_get_hdr_value_len() to know the right buffer length
Return
• ESP_OK : Field found in the request header and value string copied
• ESP_ERR_NOT_FOUND : Key not found
• ESP_ERR_INVALID_ARG : Null arguments
• ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
• ESP_ERR_HTTPD_RESULT_TRUNC : Value string truncated
Parameters
• [in] r: The request being responded to
• [in] field: The field to be searched in the header
• [out] val: Pointer to the buffer into which the value will be copied if the field is found
• [in] val_size: Size of the user buffer "val"
size_t
httpd_req_get_url_query_len(httpd_req_t
Get Query string length from the request URL.
Note This API is supposed to be called only from the context of a URI handler where httpd_req_t* request
pointer is valid
Return
• Length : Query is found in the request URL
• Zero : Query not found / Null arguments / Invalid request
Parameters
• [in] r: The request being responded to
esp_err_t httpd_req_get_url_query_str(httpd_req_t
Get Query string from the request URL.
Note
• Presently, the user can fetch the full URL query string, but decoding will have to be performed by
the user. Request headers can be read using httpd_req_get_hdr_value_str() to know the 'Content-
Type' (eg. Content-Type: application/x-www-form-urlencoded) and then the appropriate decoding
algorithm needs to be applied.
• This API is supposed to be called only from the context of a URI handler where httpd_req_t* request
pointer is valid
• If output size is greater than input, then the value is truncated, accompanied by truncation error as
return value
• Prior to calling this function, one can use httpd_req_get_url_query_len() to know the query string
length beforehand and hence allocate the buffer of right size (usually query string length + 1 for null
termination) for storing the query string
Return
• ESP_OK : Query is found in the request URL and copied to buffer
• ESP_ERR_NOT_FOUND : Query not found
• ESP_ERR_INVALID_ARG : Null arguments
• ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
• ESP_ERR_HTTPD_RESULT_TRUNC : Query string truncated
Parameters
• [in] r: The request being responded to
• [out] buf: Pointer to the buffer into which the query string will be copied (if found)
• [in] buf_len: Length of output buffer
esp_err_t
httpd_query_key_value(const char *qry, const char *key, char *val, size_t val_size)
Helper function to get a URL query tag from a query string of the type param1=val1¶m2=val2.
Espressif Systems
*r)
*r, char *buf, size_t buf_len)
577
Submit Document Feedback
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?