coreHTTP  v2.0.2
HTTP/1.1 Client Library
HTTPClient_Send

Send the request headers in HTTPRequestHeaders_t.pBuffer and request body in pRequestBodyBuf over the transport. The response is received in HTTPResponse_t.pBuffer.

HTTPRequestHeaders_t * pRequestHeaders,
const uint8_t * pRequestBodyBuf,
size_t reqBodyBufLen,
HTTPResponse_t * pResponse,
uint32_t sendFlags );

If HTTP_SEND_DISABLE_CONTENT_LENGTH_FLAG is not set in parameter sendFlags, then the Content-Length to be sent to the server is automatically written to pRequestHeaders. The Content-Length will not be written when there is no request body. If there is not enough room in the buffer to write the Content-Length then HTTPInsufficientMemory is returned. Please see HTTP_MAX_CONTENT_LENGTH_HEADER_LENGTH for the maximum Content-Length header field and value that could be written to the buffer.

The application should close the connection with the server if any of the following errors are returned:

The pResponse returned is valid only if this function returns HTTPSuccess.

Parameters
[in]pTransportTransport interface, see TransportInterface_t for more information.
[in]pRequestHeadersRequest configuration containing the buffer of headers to send.
[in]pRequestBodyBufOptional Request entity body. Set to NULL if there is no request body.
[in]reqBodyBufLenThe length of the request entity in bytes.
[in]pResponseThe response message and some notable response parameters will be returned here on success.
[in]sendFlagsFlags which modify the behavior of this function. Please see HTTPClient_Send Flags for more information.
Returns
One of the following:

Example

// Variables used in this example.
HTTPStatus_t httpLibraryStatus = HTTPSuccess;
TransportInterface_t transportInterface = { 0 };
char requestBody[] = "This is an example request body.";
// Assume that requestHeaders has been initialized with
// HTTPClient_InitializeResponseHeaders() and any additional headers have
// been added with HTTPClient_AddHeader().
HTTPRequestHeaders_t requestHeaders;
// Set the transport interface with platform specific functions that are
// assumed to be implemented elsewhere.
transportInterface.recv = myPlatformTransportReceive;
transportInterface.send = myPlatformTransportSend;
transportInterface.pNetworkContext = myPlatformNetworkContext;
// Set the buffer to receive the HTTP response message into. The buffer is
// dynamically allocated for demonstration purposes only.
response.pBuffer = ( uint8_t* )malloc( 1024 );
response.bufferLen = 1024;
httpLibraryStatus = HTTPClient_Send( &transportInterface,
&requestHeaders,
requestBody,
sizeof( requestBody ) - 1U,
&response,
0 );
if( httpLibraryStatus == HTTPSuccess )
{
if( response.status == 200 )
{
// Handle a response Status-Code of 200 OK.
}
}
HTTPSuccess
@ HTTPSuccess
The HTTP Client library function completed successfully.
Definition: core_http_client.h:173
HTTPRequestHeaders_t
Represents header data that will be sent in an HTTP request.
Definition: core_http_client.h:329
TransportInterface_t::send
TransportSend_t send
Definition: transport_interface.h:254
HTTPResponse_t
Represents an HTTP response.
Definition: core_http_client.h:434
HTTPStatus_t
HTTPStatus_t
The HTTP Client library return status.
Definition: core_http_client.h:162
HTTPClient_Send
HTTPStatus_t HTTPClient_Send(const TransportInterface_t *pTransport, HTTPRequestHeaders_t *pRequestHeaders, const uint8_t *pRequestBodyBuf, size_t reqBodyBufLen, HTTPResponse_t *pResponse, uint32_t sendFlags)
Send the request headers in HTTPRequestHeaders_t.pBuffer and request body in pRequestBodyBuf over the...
Definition: core_http_client.c:2154
TransportInterface_t::pNetworkContext
NetworkContext_t * pNetworkContext
Definition: transport_interface.h:255
TransportInterface_t::recv
TransportRecv_t recv
Definition: transport_interface.h:253
TransportInterface_t
The transport layer interface.
Definition: transport_interface.h:252