WL865E4-P  36.07.001
M2MB HTTPC

This section describes the M2MB APIs to HTTP Client operations. More...

#define M2MB_HTTPC_DEBUG_PRINT_ENABLE
 
#define M2MB_HTTPC_DBG_PRINTF   m2mb_dbg_consol_print
 
#define HTTPCLIENT_MAX_URL_LENGTH   128
 
enum  M2MB_HTTPC_RESULT {
  M2MB_HTTPC_SUCCESS = 0,
  M2MB_HTTPC_ERROR,
  M2MB_HTTPC_ERR_INVALID_PARAM,
  M2MB_HTTPC_ERR_NO_MEMORY,
  M2MB_HTTPC_ERR_NO_RESOURCE,
  M2MB_HTTPC_ERR_BUSY = 6,
  M2MB_HTTPC_ERR_NO_ENTRY,
  M2MB_HTTPC_ERR_NOT_SUPPORTED,
  M2MB_HTTPC_ERR_TIMEOUT,
  M2MB_HTTPC_ERR_BOUNDS,
  M2MB_HTTPC_ERR_BAD_PAYLOAD,
  M2MB_HTTPC_ERR_EXISTS,
  M2MB_HTTPC_CONTINUE
}
 
enum  M2MB_HTTPC_METHODS {
  M2MB_HTTPC_METHOD_INVALID = 0,
  M2MB_HTTPC_METHOD_GET_E = 1,
  M2MB_HTTPC_METHOD_HEAD_E,
  M2MB_HTTPC_METHOD_POST_E,
  M2MB_HTTPC_METHOD_PUT_E,
  M2MB_HTTPC_METHOD_DELETE_E,
  M2MB_HTTPC_METHOD_CONNECT_E,
  M2MB_HTTPC_METHOD_PATCH_E,
  M2MB_HTTPC_METHOD_MAX_E
}
 For use with m2mb_httpc_request. More...
 
enum  M2MB_HTTPC_STATES {
  M2MB_HTTPC_RX_ERROR_SERVER_CLOSED = -8,
  M2MB_HTTPC_RX_ERROR_RX_PROCESS = -7,
  M2MB_HTTPC_RX_ERROR_RX_HTTP_HEADER = -6,
  M2MB_HTTPC_RX_ERROR_INVALID_RESPONSECODE = -5,
  M2MB_HTTPC_RX_ERROR_CLIENT_TIMEOUT = -4,
  M2MB_HTTPC_RX_ERROR_NO_BUFFER = -3,
  M2MB_HTTPC_RX_CONNECTION_CLOSED = -2,
  M2MB_HTTPC_RX_ERROR_CONNECTION_CLOSED = -1,
  M2MB_HTTPC_RX_FINISHED = 0,
  M2MB_HTTPC_RX_MORE_DATA = 1
}
 HTTP client callback state. More...
 
typedef enum M2MB_HTTPC_RESULT M2MB_HTTPC_RESULT_E
 
typedef enum M2MB_HTTPC_METHODS M2MB_HTTPC_METHODS_E
 For use with m2mb_httpc_request. More...
 
typedef enum M2MB_HTTPC_STATES M2MB_HTTPC_STATES_E
 HTTP client callback state. More...
 
typedef struct M2MB_HTTPC_RESPONSE M2MB_HTTPC_RESPONSE_T
 HTTP client response. More...
 
typedef VOID(* M2MB_HTTPC_CB_T) (VOID *arg, signed int state, VOID *value)
 User registered callback for returning response message. More...
 
typedef struct M2MB_HTTPC_CTX M2MB_HTTPC_CTX_T
 
M2MB_HTTPC_RESULT_E m2mb_httpc_start ()
 (Re)starts the HTTP client module. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_stop ()
 Stops the HTTP client module. More...
 
VOIDm2mb_httpc_session_create (UINT32 timeout, M2MB_HTTPC_CB_T cb, VOID *cb_arg, UINT16 httpc_max_body_len, UINT16 httpc_max_Header_len, UINT16 httpc_Rx_Buffer_Size, VOID *m2mbSslCtx)
 create http client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_enable_http_response_header (VOID *handle, UINT16 enable)
 Enables/disables the addition of an HTTP header in a session callback. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_session_abort (VOID *handle)
 Aborts an HTTP client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_connect (VOID *handle, UINT8 *url, UINT16 port)
 Connects to an HTTP server in Blocking mode. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_disconnect (VOID *handle)
 Disconnects from an HTTP server . More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_request (VOID *handle, M2MB_HTTPC_METHODS_E method, UINT8 *url)
 Send an HTTP request to an HTTP server or proxy. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_set_request_body (VOID *handle, UINT8 *body, UINT32 body_length, UINT32 total_length)
 Sets the body on an HTTP client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_set_cgi_params (VOID *handle, UINT8 *arg, UINT8 *value)
 Forms a URL-encoded string on an HTTP client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_set_header (VOID *handle, UINT8 *hdr_name, UINT8 *hdr_value)
 Sets the header field for an HTTP client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_clear_all_headers (VOID *handle)
 Clears the header field for an HTTP client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_session_getInfo (VOID *handle, M2MB_IP46_ADDR_T *ipv6, INT32 *socket)
 Sets HTTP socket information from the http client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_send (VOID *handle, UINT8 isFirstPacket, UINT8 *body, UINT32 body_length, UINT32 total_length)
 Send HTTP information from the http client session. More...
 
M2MB_HTTPC_RESULT_E m2mb_httpc_set_request (VOID *handle, M2MB_HTTPC_METHODS_E method, UINT8 *url)
 Set the http request. More...
 

Detailed Description

This section describes the M2MB APIs to HTTP Client operations.

Macro Definition Documentation

◆ HTTPCLIENT_MAX_URL_LENGTH

#define HTTPCLIENT_MAX_URL_LENGTH   128

Definition at line 134 of file m2mb_httpc.h.

◆ M2MB_HTTPC_DBG_PRINTF

#define M2MB_HTTPC_DBG_PRINTF   m2mb_dbg_consol_print

Definition at line 52 of file m2mb_httpc.h.

◆ M2MB_HTTPC_DEBUG_PRINT_ENABLE

#define M2MB_HTTPC_DEBUG_PRINT_ENABLE

Definition at line 49 of file m2mb_httpc.h.

Typedef Documentation

◆ M2MB_HTTPC_CB_T

typedef VOID(* M2MB_HTTPC_CB_T) (VOID *arg, signed int state, VOID *value)

User registered callback for returning response message.

Parameters
[in]argArgument passed in
[in]stateState in M2MB_HTTPC_STATES_E
[in]valuePointer to M2MB_HTTPC_RESPONSE_T

Definition at line 147 of file m2mb_httpc.h.

◆ M2MB_HTTPC_CTX_T

HTTP Client context

◆ M2MB_HTTPC_METHODS_E

For use with m2mb_httpc_request.

◆ M2MB_HTTPC_RESPONSE_T

HTTP client response.

◆ M2MB_HTTPC_RESULT_E

◆ M2MB_HTTPC_STATES_E

HTTP client callback state.

Enumeration Type Documentation

◆ M2MB_HTTPC_METHODS

For use with m2mb_httpc_request.

Enumerator
M2MB_HTTPC_METHOD_INVALID 
M2MB_HTTPC_METHOD_GET_E 
M2MB_HTTPC_METHOD_HEAD_E 
M2MB_HTTPC_METHOD_POST_E 
M2MB_HTTPC_METHOD_PUT_E 
M2MB_HTTPC_METHOD_DELETE_E 
M2MB_HTTPC_METHOD_CONNECT_E 
M2MB_HTTPC_METHOD_PATCH_E 
M2MB_HTTPC_METHOD_MAX_E 

Definition at line 79 of file m2mb_httpc.h.

◆ M2MB_HTTPC_RESULT

Enumerator
M2MB_HTTPC_SUCCESS 
M2MB_HTTPC_ERROR 

= 1 (0x01) Generic failure

M2MB_HTTPC_ERR_INVALID_PARAM 

= 2 (0x02) Failure due to bad function param

M2MB_HTTPC_ERR_NO_MEMORY 

= 3 (0x03) No memory to allocate to resources

M2MB_HTTPC_ERR_NO_RESOURCE 

= 4 (0x04) Resource not found

M2MB_HTTPC_ERR_BUSY 

= 6 (0x06) Resource is busy

M2MB_HTTPC_ERR_NO_ENTRY 

= 7 (0x07)

M2MB_HTTPC_ERR_NOT_SUPPORTED 

= 8 (0x08) Feature/version not supported

M2MB_HTTPC_ERR_TIMEOUT 

= 9 (0x09) A timeout occurred and MAY be an error

M2MB_HTTPC_ERR_BOUNDS 

= 10 (0x0a) Out of bounds

M2MB_HTTPC_ERR_BAD_PAYLOAD 

= 11 (0x0b) Error in payload

M2MB_HTTPC_ERR_EXISTS 

= 12 (0x0c)

M2MB_HTTPC_CONTINUE 

= 13 (0x0c)

Definition at line 58 of file m2mb_httpc.h.

◆ M2MB_HTTPC_STATES

HTTP client callback state.

Enumerator
M2MB_HTTPC_RX_ERROR_SERVER_CLOSED 

Server closes the connection when the response has not been completely received yet.

M2MB_HTTPC_RX_ERROR_RX_PROCESS 

Size section of a chunk is longer than the RX buffer length.

M2MB_HTTPC_RX_ERROR_RX_HTTP_HEADER 

Header section is longer than the RX buffer length.

M2MB_HTTPC_RX_ERROR_INVALID_RESPONSECODE 

Status code is less than 100 or greater than 999.

M2MB_HTTPC_RX_ERROR_CLIENT_TIMEOUT 

Request times out.

M2MB_HTTPC_RX_ERROR_NO_BUFFER 

RESERVED.

M2MB_HTTPC_RX_CONNECTION_CLOSED 

RESERVED.

M2MB_HTTPC_RX_ERROR_CONNECTION_CLOSED 

Connection is closed due to error on socket read.

M2MB_HTTPC_RX_FINISHED 

Response is completely received.

M2MB_HTTPC_RX_MORE_DATA 

Response is partially received.

Definition at line 97 of file m2mb_httpc.h.

Function Documentation

◆ m2mb_httpc_clear_all_headers()

M2MB_HTTPC_RESULT_E m2mb_httpc_clear_all_headers ( VOID handle)

Clears the header field for an HTTP client session.

Parameters
[in]handleHTTP client session handle.
Returns
On success, 0 is returned, other on error code.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
}

◆ m2mb_httpc_connect()

M2MB_HTTPC_RESULT_E m2mb_httpc_connect ( VOID handle,
UINT8 url,
UINT16  port 
)

Connects to an HTTP server in Blocking mode.

Parameters
[in]handleHTTP client session handle.
[in]urlPointer to server or proxy, e.g. "192.168.2.100" or "www.example.com"
[in]portPort of the server.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
}
Returns
On success, 0 is returned; other on error code.

◆ m2mb_httpc_disconnect()

M2MB_HTTPC_RESULT_E m2mb_httpc_disconnect ( VOID handle)

Disconnects from an HTTP server .

Parameters
[in]handleHTTP client session handle.
Returns
On success, 0 is returned; other on error code.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
status = m2mb_httpc_disconnect( pHTTPcCtx->httpc_handle );
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
}

◆ m2mb_httpc_enable_http_response_header()

M2MB_HTTPC_RESULT_E m2mb_httpc_enable_http_response_header ( VOID handle,
UINT16  enable 
)

Enables/disables the addition of an HTTP header in a session callback.

By default, the system returns the message body of response via user registered callback (see M2MB_HTTPC_CB_T). Message headers are not returned. To enable the system to also return messages headers, this API should be called with 'enable'= 1.

Parameters
[in]handleHTTP client session handle.
[in]enable1 – enable; 0 – disable.
Returns
On success, 0 is returned; other on error code.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
//CONF_VAL1 defines whether to enable or disable the response header which is 1
httpc_enable_response_hdr = (UINT16)atoi(CONF_VAL1);
status = m2mb_httpc_enable_http_response_header(pHTTPcCtx->httpc_handle, httpc_enable_response_hdr);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
}

◆ m2mb_httpc_request()

M2MB_HTTPC_RESULT_E m2mb_httpc_request ( VOID handle,
M2MB_HTTPC_METHODS_E  method,
UINT8 url 
)

Send an HTTP request to an HTTP server or proxy.

Parameters
[in]handleHTTP client session handle.
[in]methodHTTP request (see M2MB_HTTPC_METHODS_E)
[in]urlPointer to the request URL, e.g. "index.html" or "/cgi/mycgi.pl"
Returns
On success, 0 is returned; other on error code.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// For Get request from Uri
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
}

◆ m2mb_httpc_send()

M2MB_HTTPC_RESULT_E m2mb_httpc_send ( VOID handle,
UINT8  isFirstPacket,
UINT8 body,
UINT32  body_length,
UINT32  total_length 
)

Send HTTP information from the http client session.

Parameters
[in]handleHTTP client session handle.
[in]isFirstPacketis Firstpacket Flag
[in]bodyis data body
[in]body_lengthis data body length
[in]total_lengthis total body length
Returns
On success, 0 is returned. On error, nonzero error code is returned.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// For SET request from Uri, METHOD TYPE M2MB_HTTPC_METHODS_E
status = m2mb_httpc_set_request( pHTTPcCtx->httpc_handle, M2MB_HTTPC_METHOD_POST_E, "FILE_PATH");
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
status = m2mb_httpc_send( pHTTPcCtx->httpc_handle, 1,body, 100, 1000);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
}

◆ m2mb_httpc_session_abort()

M2MB_HTTPC_RESULT_E m2mb_httpc_session_abort ( VOID handle)

Aborts an HTTP client session.

Disconnects from the server and frees the memory.

Parameters
[in]handleHTTP client session handle.
Returns
On success, 0 is returned; other on error code.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
status = m2mb_httpc_disconnect( pHTTPcCtx->httpc_handle );
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
if( pHTTPcCtx->httpc_handle != NULL )
{
status = m2mb_httpc_session_abort( pHTTPcCtx->httpc_handle );
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
pHTTPcCtx->httpc_handle = NULL;
}
...
}

◆ m2mb_httpc_session_create()

VOID* m2mb_httpc_session_create ( UINT32  timeout,
M2MB_HTTPC_CB_T  cb,
VOID cb_arg,
UINT16  httpc_max_body_len,
UINT16  httpc_max_Header_len,
UINT16  httpc_Rx_Buffer_Size,
VOID m2mbSslCtx 
)

create http client session.

This API creates a new http client session.

Parameters
[in]timeoutHTTP client session Timeout.
[in]cbPointer to HTTP client session callback function.
[in]cb_argPointer to the HTTP client session callback context
[in]httpc_max_body_lenHTTP client session max body length.
[in]httpc_max_Header_lenHTTP client session max header length.
[in]httpc_Rx_Buffer_SizeHTTP client session receive buffer size.
[in]m2mbSslCtxpointer to SSL context.
Returns
On success, pointer to M2MB_HTTPC_CTX_T is returned; other on error code.

Example

void httpc_cb(VOID* arg, signed int state, VOID* value);
{
...
}
int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
}

◆ m2mb_httpc_session_getInfo()

M2MB_HTTPC_RESULT_E m2mb_httpc_session_getInfo ( VOID handle,
M2MB_IP46_ADDR_T ipv6,
INT32 socket 
)

Sets HTTP socket information from the http client session.

Parameters
[in]handleHTTP client session handle.
[in]ipv6or ipv4 IP address information.
[in]socketinformation.
Returns
On success, 0 is returned and the values of IP address and socket is filled. On error, nonzero error code is returned.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
M2MB_IP46_ADDR_T IP46_addr;
status = m2mb_httpc_session_getInfo(pHTTPcCtx->httpc_handle, &IP46_addr, sd);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
}

◆ m2mb_httpc_set_cgi_params()

M2MB_HTTPC_RESULT_E m2mb_httpc_set_cgi_params ( VOID handle,
UINT8 arg,
UINT8 value 
)

Forms a URL-encoded string on an HTTP client session.

Parameters
[in]handleHTTP client session handle.
[in]argPointer to the key.
[in]valuePointer to the value.
The following calls generate a URL-encoded string which will be the message body for POST request or
the query string for GET request.
m2mb_httpc_set_cgi_params(handle, "name", "Lucy");
m2mb_httpc_set_cgi_params(handle, "neighbors", "Fred & Ethel");
For example, if user calls,
the start line, "GET /index.html?name=Lucy&neighbors=Fred+%26+Ethel HTTP/1.1\r\n", is generated.


Returns
On success, 0 is returned; other on error code.

◆ m2mb_httpc_set_header()

M2MB_HTTPC_RESULT_E m2mb_httpc_set_header ( VOID handle,
UINT8 hdr_name,
UINT8 hdr_value 
)

Sets the header field for an HTTP client session.

Parameters
[in]handleHTTP client session handle.
[in]hdr_namePointer to the type.
[in]hdr_valuePointer to the value.
Returns
On success, 0 is returned, other on error code.
Note

If this API is not called, the system will send the following headers for user:
  • Host: <hostname>:<port>
  • Accept: text/html, <asterisk>/<asterisk>
  • User-Agent: IOE Client
  • Connection: keep-alive
  • Cache-control: no-cache

Additionally, for POST, PUT and PATCH requests if message body has data:

  • Content-length: <nn>
  • Content-Type: application/x-www-form-urlencoded (for POST request)

If this API is called, the system will send the following headers for user:

  • Host: <hostname>:<port>
  • Connection: keep-alive
  • User's own headers added by calling this API

Additionally, for POST, PUT and PATCH requests if message body has data:

  • Content-length: <nn>

Example

The following calls will generate request headers in an HTTP GET request:
"User-Agent: My Own Browser 1.0\r\n"
"Connection: keep-alive\r\n"
m2mb_httpc_set_header(handle, "User-Agent", "My Own Browser 1.0");
m2mb_httpc_set_header(handle, "Connection", "keep-alive");

◆ m2mb_httpc_set_request()

M2MB_HTTPC_RESULT_E m2mb_httpc_set_request ( VOID handle,
M2MB_HTTPC_METHODS_E  method,
UINT8 url 
)

Set the http request.

Parameters
[in]handleHTTP client session handle.
[in]method
[in]url
Returns
On success, 0 is returned. On error, nonzero error code is returned.

Example

int main()
{
M2MB_HTTPC_CTX_T *pHTTPcCtx = NULL;
...
...
//role: M2MB_SSL_SSL_ROLE_E
pHTTPcCtx->ssl_handle = m2mb_ssl_init(role);
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// Start new http client session cb_arg httpClient
pHTTPcCtx = m2mb_httpc_session_create( Timeout, &httpc_cb,(void *)&httpClient, HTTPC_DEFAULT_MAX_BODY_LEN,
HTTPC_DEFAULT_MAX_HEADER_LEN, 1500, pHTTPcCtx->ssl_handle );
...
// Connect to HTTP Server
status = m2mb_httpc_connect( pHTTPcCtx->httpc_handle, SrvAddr, (UINT16)SrvPort);
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
// For SET request from Uri, METHOD TYPE M2MB_HTTPC_METHODS_E
status = m2mb_httpc_set_request( pHTTPcCtx->httpc_handle, M2MB_HTTPC_METHOD_POST_E, "FILE_PATH");
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
}

◆ m2mb_httpc_set_request_body()

M2MB_HTTPC_RESULT_E m2mb_httpc_set_request_body ( VOID handle,
UINT8 body,
UINT32  body_length,
UINT32  total_length 
)

Sets the body on an HTTP client session.

Parameters
[in]handleHTTP client session handle.
[in]bodyPointer to the http message body.
[in]body_lengthLength of the current http message body.
[in]total_lengthtotal length of http message.
Returns
On success, 0 is returned; other on error code.

◆ m2mb_httpc_start()

M2MB_HTTPC_RESULT_E m2mb_httpc_start ( )

(Re)starts the HTTP client module.

Normally, this is called to start or restart the client after it was stopped via a call to m2mb_httpc_stop().

Returns
On success, 0 is returned; other on error code.

Example

int main()
{
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
}

◆ m2mb_httpc_stop()

M2MB_HTTPC_RESULT_E m2mb_httpc_stop ( )

Stops the HTTP client module.

Returns
On success, 0 is returned; other on error code.

Example

int main()
{
...
//start HTTP client thread
status = m2mb_httpc_start();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
...
status = m2mb_httpc_stop();
if (status != M2MB_HTTPC_SUCCESS )
{
return NULL;
}
}