httpclient.h
浏览该文件的文档.
1 
10 #ifndef HTTPCLIENT_H
11 #define HTTPCLIENT_H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #include <stdbool.h>
18 #include <stdint.h>
19 
25 typedef enum {
30  HTTP_PUT
32 
34 typedef enum {
37  HTTP_ENOBUFS = -1,
38  HTTP_EARG = -2,
40  HTTP_EDNS = -4,
41  HTTP_ECONN = -5,
42  HTTP_ESEND = -6,
43  HTTP_ECLSD = -7,
44  HTTP_ERECV = -8,
45  HTTP_EPARSE = -9,
46  HTTP_EPROTO = -10,
47  HTTP_EUNKOWN = -11,
48  HTTP_ETIMEOUT = -12,
49 } HTTPC_RESULT;
50 
52 typedef struct {
53  int socket;
56  char *header;
57  char *auth_user;
58  char *auth_password;
59  bool is_http;
60 #if CONFIG_HTTP_SECURE
61  const char *server_cert;
62  const char *client_cert;
63  const char *client_pk;
64  int server_cert_len;
65  int client_cert_len;
66  int client_pk_len;
67  void *ssl;
68 #endif
69 } httpclient_t;
70 
72 typedef struct {
73  bool is_more;
74  bool is_chunked;
82  char *post_buf;
83  char *response_buf;
84  char *header_buf;
86  char* redirect_url;
88 
96 HTTPC_RESULT httpclient_get(httpclient_t *client, const char *url, httpclient_data_t *client_data);
97 
105 HTTPC_RESULT httpclient_head(httpclient_t *client, const char *url, httpclient_data_t *client_data);
106 
114 HTTPC_RESULT httpclient_post(httpclient_t *client, const char *url, httpclient_data_t *client_data);
115 
123 HTTPC_RESULT httpclient_put(httpclient_t *client, const char *url, httpclient_data_t *client_data);
124 
132 HTTPC_RESULT httpclient_delete(httpclient_t *client, const char *url, httpclient_data_t *client_data);
133 
142 HTTPC_RESULT httpclient_prepare(httpclient_data_t *client_data, int header_size, int resp_size);
143 
151 
158 
165 HTTPC_RESULT httpclient_conn(httpclient_t *client, const char *url);
166 
175 HTTPC_RESULT httpclient_send(httpclient_t *client, const char *url, int method, httpclient_data_t *client_data);
176 
184 
191 
198 void httpclient_set_custom_header(httpclient_t *client, char *header);
199 
206 
215 int httpclient_get_response_header_value(char *header_buf, char *name, int *val_pos, int *val_len);
216 
227 int httpclient_formdata_addtext(httpclient_data_t* client_data, char* content_disposition, char* content_type, char* name, char* data, int data_len);
228 
237 int httpclient_formdata_addfile(httpclient_data_t* client_data, char* content_disposition, char* name, char* content_type, char* file_path);
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif /* HTTPCLIENT_H */
HTTPC_RESULT httpclient_unprepare(httpclient_data_t *client_data)
void httpclient_set_custom_header(httpclient_t *client, char *header)
char * header
Definition: httpclient.h:56
HTTPC_RESULT httpclient_recv(httpclient_t *client, httpclient_data_t *client_data)
HTTPC_RESULT httpclient_post(httpclient_t *client, const char *url, httpclient_data_t *client_data)
HTTPC_RESULT httpclient_conn(httpclient_t *client, const char *url)
HTTPC_RESULT httpclient_send(httpclient_t *client, const char *url, int method, httpclient_data_t *client_data)
char * response_buf
Definition: httpclient.h:83
int remote_port
Definition: httpclient.h:54
void httpclient_reset(httpclient_data_t *client_data)
int httpclient_get_response_code(httpclient_t *client)
bool is_http
Definition: httpclient.h:59
HTTPC_RESULT httpclient_head(httpclient_t *client, const char *url, httpclient_data_t *client_data)
int httpclient_formdata_addfile(httpclient_data_t *client_data, char *content_disposition, char *name, char *content_type, char *file_path)
HTTPC_RESULT
http error code
Definition: httpclient.h:34
void httpclient_clse(httpclient_t *client)
char * redirect_url
Definition: httpclient.h:86
int response_code
Definition: httpclient.h:55
int httpclient_get_response_header_value(char *header_buf, char *name, int *val_pos, int *val_len)
char * post_content_type
Definition: httpclient.h:81
char * auth_password
Definition: httpclient.h:58
HTTPC_RESULT httpclient_prepare(httpclient_data_t *client_data, int header_size, int resp_size)
HTTPC_RESULT httpclient_delete(httpclient_t *client, const char *url, httpclient_data_t *client_data)
char * auth_user
Definition: httpclient.h:57
HTTPC_RESULT httpclient_put(httpclient_t *client, const char *url, httpclient_data_t *client_data)
int response_content_len
Definition: httpclient.h:76
int httpclient_formdata_addtext(httpclient_data_t *client_data, char *content_disposition, char *content_type, char *name, char *data, int data_len)
HTTP_REQUEST_TYPE
http requst type
Definition: httpclient.h:25
HTTPC_RESULT httpclient_get(httpclient_t *client, const char *url, httpclient_data_t *client_data)
@ HTTP_EPARSE
Definition: httpclient.h:45
@ HTTP_ESEND
Definition: httpclient.h:42
@ HTTP_ECONN
Definition: httpclient.h:41
@ HTTP_EPROTO
Definition: httpclient.h:46
@ HTTP_ETIMEOUT
Definition: httpclient.h:48
@ HTTP_ERECV
Definition: httpclient.h:44
@ HTTP_ENOBUFS
Definition: httpclient.h:37
@ HTTP_ECLSD
Definition: httpclient.h:43
@ HTTP_EUNKOWN
Definition: httpclient.h:47
@ HTTP_SUCCESS
Definition: httpclient.h:36
@ HTTP_EARG
Definition: httpclient.h:38
@ HTTP_EAGAIN
Definition: httpclient.h:35
@ HTTP_EDNS
Definition: httpclient.h:40
@ HTTP_ENOTSUPP
Definition: httpclient.h:39
@ HTTP_PUT
Definition: httpclient.h:30
@ HTTP_DELETE
Definition: httpclient.h:26
@ HTTP_GET
Definition: httpclient.h:27
@ HTTP_POST
Definition: httpclient.h:29
@ HTTP_HEAD
Definition: httpclient.h:28
This structure defines the HTTP data structure.
Definition: httpclient.h:72
This structure defines the httpclient_t structure
Definition: httpclient.h:52