network/http_methods/http_head.c

/*
* EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
* CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
* IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
* PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
* (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
*/
#include "common.h"
/*************************************************************************************************/
void http_head_example(void)
{
GOS_LOG("\r\n");
GOS_LOG("Running HTTP: HEAD %s", bin_url);
gos_result_t result;
gos_handle_t handle;
{
.method = GOS_HTTP_HEAD,
.url = bin_url,
};
GOS_LOG("Issuing request ... ");
if (GOS_FAILED(result, gos_http_open_request(&request, &handle)))
{
GOS_LOG("Request failed: %d", result);
return;
}
GOS_LOG("Adding custom header ... ");
if (GOS_FAILED(result, gos_http_add_header(handle, "x-my-custom-header", "custom_header_data")))
{
GOS_LOG("Failed to add header: %d", result);
return;
}
GOS_LOG("Receiving response ... ");
if (GOS_FAILED(result, gos_http_receive_response(handle, &response)))
{
GOS_LOG("Response failed: %d", result);
return;
}
GOS_LOG("Response code: %d", response.code);
gos_http_close(handle);
GOS_LOG("Success\r\n");
}