HTTP Client¶
HTTP Client library.
API Reference¶
Header File¶
Source: include/proto/httpc.h
#include <proto/httpc.h>
Functions¶
-
int httpc_client_open(void)¶
Open a new client
- Returns
On success, returns handle to http client, negative value on error
-
int httpc_client_close(int client)¶
Close a client
- Parameters
client – [in] Client handle
- Returns
0 on success, negative value on error
-
int httpc_get(int client, httpc_arg *arg)¶
Perform HTTP Get
- Parameters
client – [in] Client handle
arg – [in] HTTP client argument httpc_arg_t
- Returns
0 on success, If server response is not 2xx then server error code is returned, if any operation issue negative error code will be returned
-
int httpc_submit(int client, int method, httpc_arg *arg)¶
Perform HTTP Post, Put or Delete
- Parameters
client – [in] Client handle
method – [in] HTTP Method httpc_method_e
arg – [in] HTTP client argument httpc_arg_t
- Returns
0 on success, If server response is not 2xx then server error code is returned, if any operation issue negative error code will be returned
-
int httpc_upload(const char *url, struct http_filemeta_t *meta, char *respbuf, int *buflen)¶
HTTP file upload. This function will perform a POST with “multipart/form-data” mime on the provided URL. Its a special case of httpc_submit()
- Parameters
url – [in] URL to post
meta – [in] File information structure http_filemeta_t
respbuf – [out] Response data buffer pointer
buflen – [out] size of response data, and returns actual data stored in response buffer
- Returns
0 on success, If server response is not 2xx then server error code is returned, if any operation issue negative error code will be returned
-
int httpc_download(const char *url, char *filename, http_download_cb httpc_cb)¶
HTTP file download to local storage
- Parameters
url – [in] URL to download
filename – [in] path to filename where download file will be saved
httpc_cb – [in] Callback function called after download is finished see http_download_cb
- Returns
0 on success, If server response is not 2xx then server error code is returned, if any operation issue negative error code will be returned
-
int httpclient_set_keepalive(int client, int enable)¶
Enable or disable HTTP client keep-alive function. Keep-alive is enabled by default. If server returns a “connection: close” response then socket will be closed after execution
- Parameters
client – [in] Client handle
enable – [in] TRUE or FALSE to enable or disable respectively.
- Returns
0 on success, negative value on error
-
int httpclient_get_keepalive(int client)¶
Get current HTTP client keep-alive configuration
- Parameters
client – [in] Client handle
- Returns
On success, configuration value is returned, negative value on error
-
int urlencode(const unsigned char *in_buf, char *enc)¶
HTTP URL Encode data. Please make sure output buffer is enough to store encoded data
- Parameters
in_buf – [in] Data to encode
enc – [out] Buffer to store encoded Data
- Returns
0 on success
-
int urldecode(const char *in_buf, char *dec)¶
HTTP URL Decode data. Please make sure output buffer is enough to store decoded data
- Parameters
in_buf – [in] Input buffer containing encoded data
dec – [out] Buffere to store decoded data
- Returns
On success length of data stored in output buffer, negative value on error
Unions¶
-
union httpc_arg_t¶
- #include <httpc.h>
HTTP Client argument
Public Members
-
struct _httpc_get_t get¶
Get argument structure for httpc_get()
-
struct _httpc_post_t post¶
Post argument structure for httpc_submit()
-
struct _httpc_up_t upload¶
Upload argument structure for httpc_upload()
-
struct _httpc_get_t get¶
Structures¶
-
struct http_filemeta_t¶
HTTP File Upload information structure
Public Members
-
char *filename¶
File name (63 char max) to be uploaded with
-
char *filepath¶
Complete file path on storage media (255 max)
-
long timestamp¶
File creation UNIX timestamp
-
char *info¶
Other supplementary Info e.g. location info etc, This information is sent to server with HTTP form key “info” (127 max)
-
int filetype¶
MIME type to upload http_mimetype_e for more information
-
char *filename¶
-
struct _httpc_get_t¶
HTTP Client get argument
-
struct _httpc_post_t¶
HTTP Client post argument
Public Members
-
const char *url¶
Client URL
-
const char *header¶
Custom headers
-
const unsigned char *submit_data¶
Post data
-
int submit_len¶
Length of post data
-
int mime¶
MIME type http_mimetype_e
-
struct ssl_certs_t *certs¶
SSL Client certificate
-
int recv_headers¶
if TRUE, HTTP response headers are also stored in response buffer
-
char *resp_buffer¶
Pointer to response buffer
-
int buflen¶
Length of response buffer
-
const char *url¶
-
struct _httpc_up_t¶
HTTP Client upload argument
Public Members
-
const char *url¶
Client URL
-
const char *header¶
Custom headers
-
struct http_filemeta_t *meta¶
Upload file information http_filemeta_t
-
struct ssl_certs_t *certs¶
SSL Client certificates
-
char *respbuf¶
Pointer to response buffer
-
int buflen¶
Length of response buffer
-
const char *url¶
Macros¶
-
HTTP_RECV_HEADER¶
Indicates data is a header
-
HTTP_CLIENT_DEFAULT¶
Default HTTP client
Type Definitions¶
-
typedef void (*http_download_cb)(unsigned int dl_size, unsigned int reserved, int error)¶
HTTP download finished callback
- Param dl_size
Download size
- Param reserved
reserved
- Param error
Error code if any
-
typedef union httpc_arg_t httpc_arg¶
HTTP Client argument
Enumerations¶
-
enum http_mimetype_e¶
HTTP supported MIME types
Values:
-
enumerator HTTP_MIME_TYPE_JPEG¶
For MIME type image/jpeg
-
enumerator HTTP_MIME_TYPE_PNG¶
For MIME type image/png
-
enumerator HTTP_MIME_TYPE_JSON¶
For MIME type application/json
-
enumerator HTTP_MIME_TYPE_CSV¶
For MIME type text/csv
-
enumerator HTTP_MIME_TYPE_TXT¶
For MIME type text/plain
-
enumerator HTTP_MIME_TYPE_BINARY¶
For MIME type application/octet-stream
-
enumerator HTTP_MIME_TYPE_AMR¶
For MIME type audio/amr
-
enumerator HTTP_MIME_TYPE_AAC¶
For MIME type audio/aac
-
enumerator HTTP_MIME_TYPE_WAV¶
For MIME type audio/wav
-
enumerator HTTP_MIME_TYPE_MPEG¶
For MIME type audio/mpeg
-
enumerator HTTP_MIME_TYPE_FORM¶
For MIME type application/x-www-form-urlencoded
-
enumerator HTTP_MIME_TYPE_JPEG¶
