1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4
5 #include "httpclient.h"
6 #if AOS_COMP_CLI
7 #include "aos/cli.h"
8 #endif
9 #include <string.h>
10 #include <stdio.h>
11
12 /* @brief http request buffer */
13 #define REQ_BUF_SIZE 2048
14 static char req_buf[REQ_BUF_SIZE];
15
16 /* @brief http response buffer */
17 #define RSP_BUF_SIZE 2048
18 static char rsp_buf[RSP_BUF_SIZE];
19
http_comp_example(int argc,char ** argv)20 static void http_comp_example(int argc, char **argv)
21 {
22 httpclient_t client = {0};
23 httpclient_data_t client_data = {0};
24 char * req_url = "http://www.baidu.com/";
25 int ret;
26 char * customer_header = "Accept: */*\r\n";
27
28 if (argc > 1) {
29 req_url = argv[1];
30 }
31
32 memset(req_buf, 0, sizeof(req_buf));
33 client_data.header_buf = req_buf;
34 client_data.header_buf_len = sizeof(req_buf);
35
36 memset(rsp_buf, 0, sizeof(rsp_buf));
37 client_data.response_buf = rsp_buf;
38 client_data.response_buf_len = sizeof(rsp_buf);
39
40 printf("http request %s\r\n", req_url);
41
42 httpclient_set_custom_header(&client, customer_header);
43 ret = httpclient_get(&client, req_url, &client_data);
44 if( ret >= 0 ) {
45 printf("Data received: %s \r\n", client_data.response_buf);
46
47 printf("http comp test success!\r\n");
48 }
49
50 return;
51 }
52
53 #if AOS_COMP_CLI
54 /* reg args: fun, cmd, description*/
55 ALIOS_CLI_CMD_REGISTER(http_comp_example, http_example, http component base example)
56 #endif
57