|
|
|
@ -50,7 +50,6 @@ extern const char howsmyssl_com_root_cert_pem_end[] asm("_binary_howsmyssl_com
|
|
|
|
|
extern const char postman_root_cert_pem_start[] asm("_binary_postman_root_cert_pem_start");
|
|
|
|
|
extern const char postman_root_cert_pem_end[] asm("_binary_postman_root_cert_pem_end");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
|
|
|
|
{
|
|
|
|
|
static char *output_buffer; // Buffer to store response of http request from event handler
|
|
|
|
@ -146,7 +145,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
* If URL as well as host and path parameters are specified, values of host and path will be considered.
|
|
|
|
|
*/
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.host = "httpbin.org",
|
|
|
|
|
.host = CONFIG_EXAMPLE_HTTP_ENDPOINT,
|
|
|
|
|
.path = "/get",
|
|
|
|
|
.query = "esp",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
@ -168,7 +167,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
|
|
|
|
|
// POST
|
|
|
|
|
const char *post_data = "{\"field1\":\"value1\"}";
|
|
|
|
|
esp_http_client_set_url(client, "http://httpbin.org/post");
|
|
|
|
|
esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/post");
|
|
|
|
|
esp_http_client_set_method(client, HTTP_METHOD_POST);
|
|
|
|
|
esp_http_client_set_header(client, "Content-Type", "application/json");
|
|
|
|
|
esp_http_client_set_post_field(client, post_data, strlen(post_data));
|
|
|
|
@ -182,7 +181,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//PUT
|
|
|
|
|
esp_http_client_set_url(client, "http://httpbin.org/put");
|
|
|
|
|
esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/put");
|
|
|
|
|
esp_http_client_set_method(client, HTTP_METHOD_PUT);
|
|
|
|
|
err = esp_http_client_perform(client);
|
|
|
|
|
if (err == ESP_OK) {
|
|
|
|
@ -194,7 +193,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//PATCH
|
|
|
|
|
esp_http_client_set_url(client, "http://httpbin.org/patch");
|
|
|
|
|
esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/patch");
|
|
|
|
|
esp_http_client_set_method(client, HTTP_METHOD_PATCH);
|
|
|
|
|
esp_http_client_set_post_field(client, NULL, 0);
|
|
|
|
|
err = esp_http_client_perform(client);
|
|
|
|
@ -207,7 +206,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//DELETE
|
|
|
|
|
esp_http_client_set_url(client, "http://httpbin.org/delete");
|
|
|
|
|
esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/delete");
|
|
|
|
|
esp_http_client_set_method(client, HTTP_METHOD_DELETE);
|
|
|
|
|
err = esp_http_client_perform(client);
|
|
|
|
|
if (err == ESP_OK) {
|
|
|
|
@ -219,7 +218,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//HEAD
|
|
|
|
|
esp_http_client_set_url(client, "http://httpbin.org/get");
|
|
|
|
|
esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get");
|
|
|
|
|
esp_http_client_set_method(client, HTTP_METHOD_HEAD);
|
|
|
|
|
err = esp_http_client_perform(client);
|
|
|
|
|
if (err == ESP_OK) {
|
|
|
|
@ -236,7 +235,7 @@ static void http_rest_with_url(void)
|
|
|
|
|
static void http_rest_with_hostname_path(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.host = "httpbin.org",
|
|
|
|
|
.host = CONFIG_EXAMPLE_HTTP_ENDPOINT,
|
|
|
|
|
.path = "/get",
|
|
|
|
|
.transport_type = HTTP_TRANSPORT_OVER_TCP,
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
@ -330,7 +329,7 @@ static void http_auth_basic(void)
|
|
|
|
|
* To disable authorization retries, set max_authorization_retries to -1.
|
|
|
|
|
*/
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://user:passwd@httpbin.org/basic-auth/user/passwd",
|
|
|
|
|
.url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/basic-auth/user/passwd",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
.auth_type = HTTP_AUTH_TYPE_BASIC,
|
|
|
|
|
.max_authorization_retries = -1,
|
|
|
|
@ -351,7 +350,7 @@ static void http_auth_basic(void)
|
|
|
|
|
static void http_auth_basic_redirect(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://user:passwd@httpbin.org/basic-auth/user/passwd",
|
|
|
|
|
.url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/basic-auth/user/passwd",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
@ -372,7 +371,7 @@ static void http_auth_basic_redirect(void)
|
|
|
|
|
static void http_auth_digest(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://user:passwd@httpbin.org/digest-auth/auth/user/passwd/MD5/never",
|
|
|
|
|
.url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/digest-auth/auth/user/passwd/MD5/never",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
@ -436,7 +435,7 @@ static void https_with_hostname_path(void)
|
|
|
|
|
static void http_encoded_query(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.host = "httpbin.org",
|
|
|
|
|
.host = CONFIG_EXAMPLE_HTTP_ENDPOINT,
|
|
|
|
|
.path = "/get",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
};
|
|
|
|
@ -464,7 +463,7 @@ static void http_encoded_query(void)
|
|
|
|
|
static void http_relative_redirect(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/relative-redirect/3",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/relative-redirect/3",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
@ -483,7 +482,7 @@ static void http_relative_redirect(void)
|
|
|
|
|
static void http_absolute_redirect(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/absolute-redirect/3",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/absolute-redirect/3",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
@ -502,7 +501,7 @@ static void http_absolute_redirect(void)
|
|
|
|
|
static void http_absolute_redirect_manual(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/absolute-redirect/3",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/absolute-redirect/3",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
.disable_auto_redirect = true,
|
|
|
|
|
};
|
|
|
|
@ -522,7 +521,7 @@ static void http_absolute_redirect_manual(void)
|
|
|
|
|
static void http_redirect_to_https(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/redirect-to?url=https%3A%2F%2Fwww.howsmyssl.com",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/redirect-to?url=https://www.howsmyssl.com",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
.cert_pem = howsmyssl_com_root_cert_pem_start,
|
|
|
|
|
};
|
|
|
|
@ -543,7 +542,7 @@ static void http_redirect_to_https(void)
|
|
|
|
|
static void http_download_chunk(void)
|
|
|
|
|
{
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/stream-bytes/8912",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/stream-bytes/8912",
|
|
|
|
|
.event_handler = _http_event_handler,
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
@ -567,7 +566,7 @@ static void http_perform_as_stream_reader(void)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/get",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get",
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
|
esp_err_t err;
|
|
|
|
@ -657,7 +656,7 @@ static void http_native_request(void)
|
|
|
|
|
char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; // Buffer to store response of http request
|
|
|
|
|
int content_length = 0;
|
|
|
|
|
esp_http_client_config_t config = {
|
|
|
|
|
.url = "http://httpbin.org/get",
|
|
|
|
|
.url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get",
|
|
|
|
|
};
|
|
|
|
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
|
|
|
|
|
|
|
|
@ -686,7 +685,7 @@ static void http_native_request(void)
|
|
|
|
|
|
|
|
|
|
// POST Request
|
|
|
|
|
const char *post_data = "{\"field1\":\"value1\"}";
|
|
|
|
|
esp_http_client_set_url(client, "http://httpbin.org/post");
|
|
|
|
|
esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/post");
|
|
|
|
|
esp_http_client_set_method(client, HTTP_METHOD_POST);
|
|
|
|
|
esp_http_client_set_header(client, "Content-Type", "application/json");
|
|
|
|
|
err = esp_http_client_open(client, strlen(post_data));
|
|
|
|
|