Chapter 2. API Reference
esp_err_t esp_http_client_perform(esp_http_client_handle_t client)
Invoke this function after esp_http_client_init and all the options calls are made, and will perform
the transfer as described in the options. It must be called with the same esp_http_client_handle_t as input as
the esp_http_client_init call returned. esp_http_client_perform performs the entire request in either blocking
or non-blocking manner. By default, the API performs request in a blocking manner and returns when done,
or if it failed, and in non-blocking manner, it returns if EAGAIN/EWOULDBLOCK or EINPROGRESS is
encountered, or if it failed. And in case of non-blocking request, the user may call this API multiple times
unless request & response is complete or there is a failure. To enable non-blocking esp_http_client_perform(),
is_async member of esp_http_client_config_t must be set while making a call to esp_http_client_init() API.
You can do any amount of calls to esp_http_client_perform while using the same esp_http_client_handle_t.
The underlying connection may be kept open if the server allows it. If you intend to transfer more than one
file, you are even encouraged to do so. esp_http_client will then attempt to re-use the same connection for
the following transfers, thus making the operations faster, less CPU intense and using less network resources.
Just note that you will have to use esp_http_client_set_** between the invokes to set options for the
following esp_http_client_perform.
Note You must never call this function simultaneously from two places using the same client handle.
Let the function return first before invoking it another time. If you want parallel transfers, you
must use several esp_http_client_handle_t. This function include esp_http_client_open
-> esp_http_client_write -> esp_http_client_fetch_headers ->
esp_http_client_read (and option) esp_http_client_close.
Return
• ESP_OK on successful
• ESP_FAIL on error
Parameters
• client: The esp_http_client handle
esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *url)
Set URL for client, when performing this behavior, the options in the URL will replace the old ones.
Return
• ESP_OK
• ESP_FAIL
Parameters
• [in] client: The esp_http_client handle
• [in] url: The url
esp_err_t esp_http_client_set_post_field(esp_http_client_handle_t client, const char *data,
int len)
Set post data, this function must be called before esp_http_client_perform. Note: The data param-
eter passed to this function is a pointer and this function will not copy the data.
Return
• ESP_OK
• ESP_FAIL
Parameters
• [in] client: The esp_http_client handle
• [in] data: post data pointer
• [in] len: post length
int esp_http_client_get_post_field(esp_http_client_handle_t client, char **data)
Get current post field information.
Return Size of post data
Parameters
• [in] client: The client
• [out] data: Point to post data pointer
esp_err_t esp_http_client_set_header(esp_http_client_handle_t client, const char *key, const
char *value)
Set http request header, this function must be called after esp_http_client_init and before any perform function.
Return
Espressif Systems 561
Submit Document Feedback
Release v4.4