![]() |
WE310F5
39.00.000
|
This section describes the M2MB APIs to HTTP Client operations. More...
This section describes the M2MB APIs to HTTP Client operations.
HTTP Client APIs can be used to communicate with HTTP server. The diagram shows the sequence of API call to be performed. To connect to a HTTP server and exchange information, the following steps must be performed:
#define M2MB_HTTPCLIENT_MAX_HOST_LENGTH 64 |
Definition at line 78 of file m2mb_httpc.h.
#define M2MB_HTTPCLIENT_MAX_URL_LENGTH 1024 |
Definition at line 77 of file m2mb_httpc.h.
typedef VOID(* M2MB_HTTPC_CB_T) (VOID *arg, M2MB_HTTPC_STATES_E state, M2MB_HTTPC_RESPONSE_T *value) |
User registered callback for returning response message.
This callback function is called when http response is received from the server. This callback function is called from internal http client thread. The data must be consumed during the callback function.
The received data can be chunked encoded or normal. case 1: if enable_rsp_header enabled: 1st callback : Contains response headers with M2MB_HTTPC_RX_MORE_DATA 2nd and subsequent calls : Contains the data with with M2MB_HTTPC_RX_MORE_DATA. last callback : Contains the data with M2MB_HTTPC_RX_FINISHED. case 2: if enable_rsp_header disabled :
1nd and subsequent calls : Contains the data with with M2MB_HTTPC_RX_MORE_DATA. last callback : Contains the data with M2MB_HTTPC_RX_FINISHED.
[in] | arg | Argument user provided callback context during m2mb_httpc_open() |
[in] | state | State in M2MB_HTTPC_STATES_E |
[in] | value | Pointer to M2MB_HTTPC_RESPONSE_T Example { M2MB_HTTPC_RESPONSE_T rsp = {0 }; return; // data finished or more data if(state >= M2MB_HTTPC_RX_FINISHED) { rsp = ( M2MB_HTTPC_RESPONSE_T *)value; // got the response from the server // print the response data if length is valid } else { M2MB_DBG_INFO("Error recevied %d", state); } } |
Definition at line 213 of file m2mb_httpc.h.
typedef enum M2MB_HTTPC_CONF_ID M2MB_HTTPC_CONF_ID_E |
HTTP client confg id for use in m2mb_http_set_cfg and m2mb_httpc_get_cfg APIs.
typedef union M2MB_HTTPC_CONF_PARAMS M2MB_HTTPC_CONF_PARAMS_T |
HTTP client configuration params structure for use in m2mb_http_set_cfg and m2mb_httpc_get_cfg APIs.
typedef HANDLE M2MB_HTTPC_CTXT_HANDLE |
HTTPC context handle.
This is obtained from m2mb_httpc_open API and then used in subsequent HTTPC APIs.
Definition at line 82 of file m2mb_httpc.h.
typedef enum M2MB_HTTPC_METHODS M2MB_HTTPC_METHODS_E |
supported http request method for use with m2mb_httpc_request.
typedef struct M2MB_HTTPC_OPEN_PARAMS M2MB_HTTPC_OPEN_PARAMS_T |
HTTPC parameters required to open a client connection.
The structure is used in m2mb_httpc_open() for setting http client context.
typedef struct M2MB_HTTPC_RESPONSE M2MB_HTTPC_RESPONSE_T |
HTTP client response for use in user callback.
typedef enum M2MB_HTTPC_STATES M2MB_HTTPC_STATES_E |
HTTP client callback state.
enum M2MB_HTTPC_CONF_ID |
HTTP client confg id for use in m2mb_http_set_cfg and m2mb_httpc_get_cfg APIs.
Definition at line 127 of file m2mb_httpc.h.
enum M2MB_HTTPC_METHODS |
supported http request method for use with m2mb_httpc_request.
Enumerator | |
---|---|
M2MB_HTTPC_METHOD_INVALID | |
M2MB_HTTPC_METHOD_GET | |
M2MB_HTTPC_METHOD_HEAD | |
M2MB_HTTPC_METHOD_POST | |
M2MB_HTTPC_METHOD_PUT | |
M2MB_HTTPC_METHOD_MAX |
Definition at line 86 of file m2mb_httpc.h.
enum M2MB_HTTPC_STATES |
HTTP client callback state.
Definition at line 99 of file m2mb_httpc.h.
M2MB_STATUS_T m2mb_httpc_close | ( | HANDLE | handle | ) |
closes an HTTP client session.
Closes from the server and frees the memory. This function internally takes case of disconnection from server. This API can be called anytime after m2mb_httpc_open()
[in] | handle | HTTP client session handle. |
Example
M2MB_STATUS_T m2mb_httpc_connect | ( | HANDLE | handle, |
UINT8 * | url, | ||
UINT16 | port | ||
) |
Connects to an HTTP server in Blocking mode.
[in] | handle | HTTP client session handle. |
[in] | url | Pointer to server or proxy, e.g. "192.168.2.100" or "www.example.com" |
[in] | port | Port of the server. |
M2MB_STATUS_T m2mb_httpc_get_cfg | ( | HANDLE | handle, |
M2MB_HTTPC_CONF_ID_E | conf_id, | ||
M2MB_HTTPC_CONF_PARAMS_T * | conf_params | ||
) |
get the http client session information
This function is used to get various HTTP Client options. Based on the conf id the configuration value is used. This api must be used after m2mb_httpc_connect().
[in] | handle | HTTP client session handle. |
[in] | conf_id | HTTP Configuration ID. The following configuration ID's are supported : M2MB_HTTPC_CONF_GET_SERVER_IP : To get the http server IP address M2MB_HTTPC_CONF_GET_SOCK_ID : To get the connection socket ID |
[out] | conf_params | pointer to M2MB_HTTPC_CONF_PARAMS_T struct. The information will be filled based on the CONF ID provided. Mapping of CONF_ID to CONF_PARAMS struct: M2MB_HTTPC_CONF_GET_SERVER_IP : conf_params.IP46_addr M2MB_HTTPC_CONF_GET_SOCK_ID : conf_params.sockId |
M2MB_STATUS_T m2mb_httpc_open | ( | HANDLE * | hndl, |
M2MB_HTTPC_OPEN_PARAMS_T * | params | ||
) |
create http client context
This API creates a new http client context.
[out] | hndl | pointer to M2MB_HTTPC_CTXT_HANDLE |
[in] | params | pointer to structure of type M2MB_HTTPC_OPEN_PARAMS_T. |
M2MB_STATUS_T m2mb_httpc_send | ( | VOID * | handle, |
UINT8 | isFirstPacket, | ||
UINT8 * | body, | ||
UINT32 | body_length, | ||
UINT32 | total_length | ||
) |
Send HTTP information from the http client session.
[in] | handle | HTTP client session handle. |
[in] | isFirstPacket | If isFirstPacket set to TRUE then HTTP hraders will be sent in the packet. |
[in] | body | is data body |
[in] | body_length | is data body length |
[in] | total_length | is total body length |
Example
M2MB_STATUS_T m2mb_httpc_set_cfg | ( | HANDLE | handle, |
M2MB_HTTPC_CONF_ID_E | conf_id, | ||
M2MB_HTTPC_CONF_PARAMS_T * | conf_params | ||
) |
update the http client session configurations
This function is used to set various HTTP Client options. Based on the conf id the configuration value is used. This api must be used before m2mb_httpc_connect().
[in] | handle | HTTP client session handle. |
[in] | conf_id | HTTP Configuration ID. The following configuration ID's are supported : M2MB_HTTPC_CONF_SET_HEADER : set header M2MB_HTTPC_CONF_SET_CGI_PARAMS : set cgi params M2MB_HTTPC_CONF_ENABLE_RESP_HEADER : enable response header M2MB_HTTPC_CONF_CLEAR_ALL_HEADER : clear all headers |
[in] | conf_params | struct of type M2MB_HTTPC_CONF_PARAMS_T Mapping of CONF_ID to CONF_PARAMS Structure: M2MB_HTTPC_CONF_SET_HEADER : confParams.param.header_name confParams.param.header_val M2MB_HTTPC_CONF_ENABLE_RESP_HEADER : confParams.param.enable_rsp_header M2MB_HTTPC_CONF_CLEAR_ALL_HEADER : NULL |
M2MB_STATUS_T m2mb_httpc_set_request | ( | VOID * | handle, |
M2MB_HTTPC_METHODS_E | method, | ||
UINT8 * | url | ||
) |
Set the http request.
[in] | handle | HTTP client session handle. |
[in] | method | |
[in] | url |
Example