HTTP Client API 参考
Macros
-
WM_HTTP_CLIENT_INVALID
invalid http client handle.
Enumerations
-
enum wm_http_auth_achema
Enumeration of HTTP authentication schemes.
This enumeration lists the various authentication schemes that can be used with the HTTP client.
Values:
-
enumerator WM_HTTP_CLIENT_AUTH_NONE
HTTP not use authentication.
-
enumerator WM_HTTP_CLIENT_AUTH_BASIC
HTTP use basic authentication.
-
enumerator WM_HTTP_CLIENT_AUTH_DIGEST
HTTP use digest authentication.
-
enumerator WM_HTTP_CLIENT_AUTH_KERBEROS
HTTP use kerberos authentication.
-
enumerator WM_HTTP_CLIENT_AUTH_MAX
HTTP not support authentication.
-
enumerator WM_HTTP_CLIENT_AUTH_NONE
-
enum wm_http_client_request_type_t
Enumeration of HTTP client request types.
This enumeration lists the different types of HTTP requests that can be made by the client.
Values:
-
enumerator WM_HTTP_CLIENT_REQUEST_TYPE_GET
HTTP Client GET request.
-
enumerator WM_HTTP_CLIENT_REQUEST_TYPE_HEAD
HTTP Client HEAD request.
-
enumerator WM_HTTP_CLIENT_REQUEST_TYPE_POST
HTTP Client POST request.
-
enumerator WM_HTTP_CLIENT_REQUEST_TYPE_PUT
HTTP Client PUT request.
-
enumerator WM_HTTP_CLIENT_REQUEST_TYPE_DELETE
HTTP Client DELETE request.
-
enumerator WM_HTTP_CLIENT_REQUEST_TYPE_GET
-
enum wm_http_client_content_type_t
Enumeration of HTTP client content types.
This enumeration defines the various content types that can be specified for HTTP requests.
Values:
-
enumerator WM_HTTP_CLIENT_CONTENT_NONE
not set content type header.
-
enumerator WM_HTTP_CLIENT_CONTENT_APPLICATION_URLENCODED
application/x-www-form-urlencoded.
-
enumerator WM_HTTP_CLIENT_CONTENT_APPLICATION_JSON
application/json.
-
enumerator WM_HTTP_CLIENT_CONTENT_MULTIPART_FORM_DATA
multipart/form-data.
-
enumerator WM_HTTP_CLIENT_CONTENT_TEXT_XML
text/xml.
-
enumerator WM_HTTP_CLIENT_CONTENT_NONE
-
enum wm_http_client_event_t
Enumeration of HTTP client events.
This enumeration lists the events that can occur within the HTTP client.
Values:
-
enumerator WM_HTTP_CLIENT_EVENT_CONNECTED
Event indicating a connection has been established.
-
enumerator WM_HTTP_CLIENT_EVENT_DISCONNECTED
Event indicating a disconnection.
-
enumerator WM_HTTP_CLIENT_EVENT_HEADER_SENTED
Event indicating headers have been sent.
-
enumerator WM_HTTP_CLIENT_EVENT_RECV_HEADER
Event indicating headers have been received.
-
enumerator WM_HTTP_CLIENT_EVENT_RECV_DATA
Event indicating data has been received.
-
enumerator WM_HTTP_CLIENT_EVENT_FINISH
Event indicating the end of a transaction.
-
enumerator WM_HTTP_CLIENT_EVENT_CONNECTED
-
typedef enum wm_http_auth_achema wm_http_client_auth_schema_t
Enumeration of HTTP authentication schemes.
This enumeration lists the various authentication schemes that can be used with the HTTP client.
Structures
-
typedef struct wm_http_client_event_param wm_http_client_event_param_t
Structure for HTTP client event parameters.
This structure is used to pass parameters related to HTTP client events.
-
typedef struct wm_http_client_config wm_http_client_config_t
Structure for HTTP client configuration.
This structure is used to configure the settings for an HTTP client session.
-
struct wm_http_client_event_param
Structure for HTTP client event parameters.
This structure is used to pass parameters related to HTTP client events.
-
struct wm_http_client_config
Structure for HTTP client configuration.
This structure is used to configure the settings for an HTTP client session.
Public Members
-
char *username
User name of the HTTP session.
-
char *password
Password of the HTTP session.
-
wm_http_client_auth_schema_t auth_type
HTTP Supported authentication methods.
-
char *user_agent
The User Agent string to send with HTTP requests.
-
wm_http_client_request_type_t method
Request type of the HTTP client.
-
wm_http_client_content_type_t content_type
Format of HTTP data.
-
bool keep_alive
Set the keep alive header.
-
bool no_cache
Set the no cache header.
-
bool use_proxy
Whether to use the HTTP proxy.
-
uint16_t proxy_port
HTTP proxy port name.
-
char *proxy_host
HTTP proxy host name.
-
wm_http_client_event_handle event_handler
client event handler.
-
void *priv
This is an optional temporary parameter.
-
char *username
Type Definitions
-
typedef HTTP_SESSION_HANDLE wm_http_client_t
Type definition for an HTTP session handle.
This type is used to represent a handle to an HTTP session.
-
typedef HTTP_CLIENT wm_http_client_info_t
Type definition for HTTP client information.
This type is used to store information related to the HTTP client.
-
typedef void (*wm_http_client_event_handle)(wm_http_client_t session, wm_http_client_event_t event, wm_http_client_event_param_t *data, void *priv)
Type definition for an HTTP client event handler function.
This type defines a function pointer that can be used as an event handler for the HTTP client. It is called when various events occur within the HTTP client.
Functions
-
wm_http_client_t wm_http_client_open_request(const wm_http_client_config_t *client_config)
Allocate memory for a new HTTP client.
- 参数:
client_config – HTTP client config.
- 返回:
WM_HTTP_CLIENT_INVALID: failed
others: succeed
-
int wm_http_client_close_request(wm_http_client_t *session)
Closes any active connection and free any used memory.
- 参数:
session – HTTP client handle.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_set_no_cache(wm_http_client_t session, bool no_cache)
Set the HTTP client to tell the browser that it does not cache directly, but must request it from the server.
- 参数:
session – HTTP client handle.
no_cache – TRUE: enable no_cache header. FALSE: disable no_cache header.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_set_keepalive(wm_http_client_t session, bool keepalive)
Set the keepalive on the HTTP client.
- 参数:
session – HTTP client handle.
keepalive – TRUE: enable keepalive header. FALSE: disable keepalive header.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_set_auth(wm_http_client_t session, wm_http_client_auth_schema_t auth_schema)
Sets the HTTP authentication schema.
- 参数:
session – HTTP client handle.
auth_schema – HTTP Supported authentication methods.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_set_credentials(wm_http_client_t session, char *user_name, char *password)
Sets credentials for the target host.
- 参数:
session – HTTP client handle.
user_name – User name.
password – Password.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_set_proxy(wm_http_client_t session, char *proxy_name, uint16_t port, char *user_name, char *password)
Sets all the proxy related parameters.
- 参数:
session – HTTP client handle.
proxy_name – The host name.
port – The proxy port number.
user_name – User name for proxy authentication (can be null).
password – User password for proxy authentication (can be null).
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_set_verb(wm_http_client_t session, wm_http_client_request_type_t http_verb)
Sets the HTTP verb for the outgoing request.
- 参数:
session – HTTP client handle.
http_verb – HTTP supported verbs.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_add_request_headers(wm_http_client_t session, char *header_name, char *header_data)
Add headers to the outgoing request.
- 参数:
session – HTTP client handle.
header_name – The Headers name.
header_data – The headers data. It can be NULL, if it is empty, the header simply uses header_name without adding “\r\n” to the end.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_send_request(wm_http_client_t session, char *url, void *data, uint32_t data_len, bool data_len_valid, uint32_t time_out, uint32_t client_port)
This function builds the request headers, performs a DNS resolution , opens the connection (if it was not opened yet by a previous request or if it has closed) and sends the request headers.
- 参数:
session – HTTP client handle.
url – The requested URL.
data – Data to post to the server.
data_len – Length of posted data.
data_len_valid – Valid only when HTTP method is post. TRUE: data_len is valid when post data to HTTP server. FALSE: data_len is invalid, in a post request without knowing the total length in advance so return error or use chunking.
time_out – Operation timeout, the unit is milliseconds. A value of 0 defaults to 30s.
client_port – Client side port 0 for none (bind local port).
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_write_data(wm_http_client_t session, void *buffer, uint32_t buffer_len, uint32_t time_out)
Write data to the remote server.
- 参数:
session – HTTP client handle.
buffer – Data to write to the server.
buffer_len – Length of wtitten data.
time_out – Timeout for the operation, the unit is milliseconds. A value of 0 defaults to 30s.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_recv_response(wm_http_client_t session, uint32_t time_out)
Receives the response header on the connection and parses it. Performs any required authentication.
- 参数:
session – HTTP client handle.
time_out – Timeout for the operation, the unit is milliseconds.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_read_data(wm_http_client_t session, void *buffer, uint32_t bytes_to_read, uint32_t time_out, uint32_t *bytes_recived)
Read data from the server. Parse out the chunks data.
- 参数:
session – [in] HTTP client handle.
buffer – [out] A pointer to a buffer that will be filled with the servers response.
bytes_to_read – [in] The size of the buffer (numbers of bytes to read).
time_out – [in] Timeout for the operation, the unit is milliseconds. A value of 0 defaults to 30s.
bytes_recived – [out] Count of the bytes that were received in this operation.
- 返回:
WM_ERR_SUCCESS: succeed
WM_ERR_EOS: end of stream
others: failed
-
int wm_http_client_get_info(wm_http_client_t session, wm_http_client_info_t *http_client)
Fill the users structure with the session information.
- 参数:
session – [in] HTTP client handle.
http_client – [out] The session information.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_find_first_header(wm_http_client_t session, char *search_clue, char *header_buffer, uint32_t *length)
Initiate the headr searching functions and find the first header.
- 参数:
session – [in] HTTP client handle.
search_clue – [in] Search clue.
header_buffer – [out] A pointer to a buffer that will be filled with the header name and value.
length – [out] Count of the bytes that were received in this operation.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_get_next_header(wm_http_client_t session, char *header_buffer, uint32_t *length)
Find the next header.
- 参数:
session – [in] HTTP client handle.
header_buffer – [out] A pointer to a buffer that will be filled with the header name and value.
length – [out] Count of the bytes that were received in this operation.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_http_client_find_close_header(wm_http_client_t session)
Terminate a headers search session.
- 参数:
session – HTTP client handle.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed