http

结构体

struct  httpclient_t
 This structure defines the httpclient_t structure
更多...
 
struct  httpclient_data_t
 This structure defines the HTTP data structure.
更多...
 

枚举

enum  HTTP_REQUEST_TYPE {
  HTTP_DELETE , HTTP_GET , HTTP_HEAD , HTTP_POST ,
  HTTP_PUT
}
 http requst type 更多...
 
enum  HTTPC_RESULT {
  HTTP_EAGAIN = 1 , HTTP_SUCCESS = 0 , HTTP_ENOBUFS = -1 , HTTP_EARG = -2 ,
  HTTP_ENOTSUPP = -3 , HTTP_EDNS = -4 , HTTP_ECONN = -5 , HTTP_ESEND = -6 ,
  HTTP_ECLSD = -7 , HTTP_ERECV = -8 , HTTP_EPARSE = -9 , HTTP_EPROTO = -10 ,
  HTTP_EUNKOWN = -11 , HTTP_ETIMEOUT = -12
}
 http error code 更多...
 

函数

HTTPC_RESULT httpclient_get (httpclient_t *client, const char *url, httpclient_data_t *client_data)
 
HTTPC_RESULT httpclient_head (httpclient_t *client, const char *url, httpclient_data_t *client_data)
 
HTTPC_RESULT httpclient_post (httpclient_t *client, const char *url, httpclient_data_t *client_data)
 
HTTPC_RESULT httpclient_put (httpclient_t *client, const char *url, httpclient_data_t *client_data)
 
HTTPC_RESULT httpclient_delete (httpclient_t *client, const char *url, httpclient_data_t *client_data)
 
HTTPC_RESULT httpclient_prepare (httpclient_data_t *client_data, int header_size, int resp_size)
 
HTTPC_RESULT httpclient_unprepare (httpclient_data_t *client_data)
 
void httpclient_reset (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)
 
HTTPC_RESULT httpclient_recv (httpclient_t *client, httpclient_data_t *client_data)
 
void httpclient_clse (httpclient_t *client)
 
void httpclient_set_custom_header (httpclient_t *client, char *header)
 
int httpclient_get_response_code (httpclient_t *client)
 
int httpclient_get_response_header_value (char *header_buf, char *name, int *val_pos, int *val_len)
 
int httpclient_formdata_addtext (httpclient_data_t *client_data, char *content_disposition, char *content_type, char *name, char *data, int data_len)
 
int httpclient_formdata_addfile (httpclient_data_t *client_data, char *content_disposition, char *name, char *content_type, char *file_path)
 

变量

int socket
 
int remote_port
 
int response_code
 
char * header
 
char * auth_user
 
char * auth_password
 
bool is_http
 
bool is_more
 
bool is_chunked
 
int retrieve_len
 
int response_content_len
 
int content_block_len
 
int post_buf_len
 
int response_buf_len
 
int header_buf_len
 
char * post_content_type
 
char * post_buf
 
char * response_buf
 
char * header_buf
 
bool is_redirected
 
char * redirect_url
 

详细描述

枚举类型说明

◆ HTTP_REQUEST_TYPE

http requst type

枚举值
HTTP_DELETE 
HTTP_GET 
HTTP_HEAD 
HTTP_POST 
HTTP_PUT 

在文件 httpclient.h25 行定义.

◆ HTTPC_RESULT

http error code

枚举值
HTTP_EAGAIN 

more data to retrieved

HTTP_SUCCESS 

operation success

HTTP_ENOBUFS 

buffer error

HTTP_EARG 

illegal argument

HTTP_ENOTSUPP 

not support

HTTP_EDNS 

DNS fail

HTTP_ECONN 

connect fail

HTTP_ESEND 

send packet fail

HTTP_ECLSD 

connect closed

HTTP_ERECV 

recv packet fail

HTTP_EPARSE 

url parse error

HTTP_EPROTO 

protocol error

HTTP_EUNKOWN 

unknown error

HTTP_ETIMEOUT 

timeout

在文件 httpclient.h34 行定义.

函数说明

◆ httpclient_clse()

void httpclient_clse ( httpclient_t client)

This function close http connection.

参数
[in]clientclient is a pointer to the httpclient_t.
返回
None.

◆ httpclient_conn()

HTTPC_RESULT httpclient_conn ( httpclient_t client,
const char *  url 
)

This function establish http/https connection.

参数
[in]clientpointer to the httpclient_t.
[in]urlremote URL
返回
Please refer to HTTPC_RESULT.

◆ httpclient_delete()

HTTPC_RESULT httpclient_delete ( httpclient_t client,
const char *  url,
httpclient_data_t client_data 
)

This function executes a DELETE request on a given URL. It blocks until completion.

参数
[in]clientclient is a pointer to the httpclient_t.
[in]urlurl is the URL to run the request.
[in,out]client_dataclient_data is a pointer to the httpclient_data_t instance to collect the data returned by the request.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_formdata_addfile()

int httpclient_formdata_addfile ( httpclient_data_t client_data,
char *  content_disposition,
char *  name,
char *  content_type,
char *  file_path 
)

This function add file formdata information.

参数
[in]client_dataclient_data is a pointer to the httpclient_data_t.
[in]content_dispositioncontent_disposition is a pointer to the content disposition string.
[in]content_typecontent_type is a pointer to the content type string.
[in]file_pathfile_path is a pointer to the file path.
返回
The HTTP response code of the last request.

◆ httpclient_formdata_addtext()

int httpclient_formdata_addtext ( httpclient_data_t client_data,
char *  content_disposition,
char *  content_type,
char *  name,
char *  data,
int  data_len 
)

This function add text formdata information.

参数
[in]client_dataclient_data is a pointer to the httpclient_data_t.
[in]content_dispositioncontent_disposition is a pointer to the content disposition string.
[in]content_typecontent_type is a pointer to the content type string.
[in]namename is a pointer to the name string.
[in]datadata is a pointer to the data.
[in]data_lendata_len is the data length.
返回
The HTTP response code of the last request.

◆ httpclient_get()

HTTPC_RESULT httpclient_get ( httpclient_t client,
const char *  url,
httpclient_data_t client_data 
)

This function executes a GET request on a given URL. It blocks until completion.

参数
[in]clientclient is a pointer to the httpclient_t.
[in]urlurl is the URL to run the request.
[in,out]client_dataclient_data is a pointer to the httpclient_data_t instance to collect the data returned by the request.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_get_response_code()

int httpclient_get_response_code ( httpclient_t client)

This function gets the HTTP response code assigned to the last request.

参数
[in]clientclient is a pointer to the httpclient_t.
返回
The HTTP response code of the last request.

◆ httpclient_get_response_header_value()

int httpclient_get_response_header_value ( char *  header_buf,
char *  name,
int *  val_pos,
int *  val_len 
)

This function get specified response header value.

参数
[in]header_bufheader_buf is the response header buffer.
[in]namename is the specified http response header name.
[in,out]val_posval_pos is the position of header value in header_buf.
[in,out]val_lenval_len is header value length.
返回
0, if value is got. Others, if errors occurred.

◆ httpclient_head()

HTTPC_RESULT httpclient_head ( httpclient_t client,
const char *  url,
httpclient_data_t client_data 
)

This function executes a HEAD request on a given URL. It blocks until completion.

参数
[in]clientclient is a pointer to the httpclient_t.
[in]urlurl is the URL to run the request.
[in,out]client_dataclient_data is a pointer to the httpclient_data_t instance to collect the data returned by the request.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_post()

HTTPC_RESULT httpclient_post ( httpclient_t client,
const char *  url,
httpclient_data_t client_data 
)

This function executes a POST request on a given URL. It blocks until completion.

参数
[in]clientclient is a pointer to the httpclient_t.
[in]urlurl is the URL to run the request.
[in,out]client_dataclient_data is a pointer to the httpclient_data_t instance to collect the data returned by the request. It also contains the data to be posted.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_prepare()

HTTPC_RESULT httpclient_prepare ( httpclient_data_t client_data,
int  header_size,
int  resp_size 
)

This function allocates buffer for http header/response

参数
[in]client_datapointer to the httpclient_data_t.
[in]header_sizeheader buffer size
[in]resp_sizeresponse buffer size
返回
HTTP_SUCCESS success
HTTP_EUNKOWN fail

◆ httpclient_put()

HTTPC_RESULT httpclient_put ( httpclient_t client,
const char *  url,
httpclient_data_t client_data 
)

This function executes a PUT request on a given URL. It blocks until completion.

参数
[in]clientclient is a pointer to the httpclient_t.
[in]urlurl is the URL to run the request.
[in,out]client_dataclient_data is a pointer to the httpclient_data_t instance to collect the data returned by the request. It also contains the data to be put.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_recv()

HTTPC_RESULT httpclient_recv ( httpclient_t client,
httpclient_data_t client_data 
)

This function receives response from remote

参数
[in]clienta pointer to httpclient_t.
[out]client_dataa pointer to httpclient_data_t.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_reset()

void httpclient_reset ( httpclient_data_t client_data)

This function reset buffer for http header/response.

参数
[in]client_datapointer to the httpclient_data_t.
返回
None.

◆ httpclient_send()

HTTPC_RESULT httpclient_send ( httpclient_t client,
const char *  url,
int  method,
httpclient_data_t client_data 
)

This function sends HTTP request.

参数
[in]clienta pointer to the httpclient_t.
[in]urlremote URL
[in]methodhttp request method
[in]client_dataa pointer to httpclient_data_t.
返回
Please refer to HTTPC_RESULT.

◆ httpclient_set_custom_header()

void httpclient_set_custom_header ( httpclient_t client,
char *  header 
)

This function sets a custom header.

参数
[in]clientclient is a pointer to the httpclient_t.
[in]headerheader is a custom header string.
返回
None.

◆ httpclient_unprepare()

HTTPC_RESULT httpclient_unprepare ( httpclient_data_t client_data)

This function deallocates buffer for http header/response.

参数
[in]client_datapointer to the httpclient_data_t.
返回
HTTP_SUCCESS success
HTTP_EUNKOWN fail

变量说明

◆ auth_password

char* auth_password

password for basic authentication

在文件 httpclient.h58 行定义.

◆ auth_user

char* auth_user

username for basic authentication

在文件 httpclient.h57 行定义.

◆ content_block_len

int content_block_len

the content length of one block.

在文件 httpclient.h77 行定义.

◆ header

char* header

request custom header

在文件 httpclient.h56 行定义.

◆ header_buf

char* header_buf

buffer to store the response head data.

在文件 httpclient.h84 行定义.

◆ header_buf_len

int header_buf_len

response head buffer lehgth.

在文件 httpclient.h80 行定义.

◆ is_chunked

bool is_chunked

response data is encoded in portions/chunks.

在文件 httpclient.h74 行定义.

◆ is_http

bool is_http

http connection? if 1, http; if 0, https

在文件 httpclient.h59 行定义.

◆ is_more

bool is_more

indicates if more data needs to be retrieved.

在文件 httpclient.h73 行定义.

◆ is_redirected

bool is_redirected

redirected URL? if 1, has redirect url; if 0, no redirect url

在文件 httpclient.h85 行定义.

◆ post_buf

char* post_buf

user data to be posted.

在文件 httpclient.h82 行定义.

◆ post_buf_len

int post_buf_len

post data length.

在文件 httpclient.h78 行定义.

◆ post_content_type

char* post_content_type

content type of the post data.

在文件 httpclient.h81 行定义.

◆ redirect_url

char* redirect_url

redirect url when got http 3** response code.

在文件 httpclient.h86 行定义.

◆ remote_port

int remote_port

hTTP or HTTPS port

在文件 httpclient.h54 行定义.

◆ response_buf

char* response_buf

buffer to store the response body data.

在文件 httpclient.h83 行定义.

◆ response_buf_len

int response_buf_len

response body buffer length.

在文件 httpclient.h79 行定义.

◆ response_code

int response_code

response code

在文件 httpclient.h55 行定义.

◆ response_content_len

int response_content_len

response content length.

在文件 httpclient.h76 行定义.

◆ retrieve_len

int retrieve_len

content length to be retrieved.

在文件 httpclient.h75 行定义.

◆ socket

int socket

socket ID

在文件 httpclient.h53 行定义.