BK Controller HTTP Development Guide
Preface
Overview
This document mainly introduces the BEKEN Controller HTTP Client function development implementation examples.
Product Version
The product versions corresponding to this document are as follows:
Product Name
Product Version
BK7239N
V1.0
Target Audience
This document is mainly applicable to the following audiences:
Technical Support Engineers
Software Development Engineers
Symbol Conventions
The following symbols may appear in this document, and their meanings are as follows:
Symbol
Description
![]()
Indicates a high-risk hazard that will cause death or serious injury if not avoided.
![]()
Indicates a medium-risk hazard that may cause death or serious injury if not avoided.
![]()
Indicates a low-risk hazard that may cause minor or moderate injury if not avoided.
![]()
Used to convey device or environmental safety warning information. If not avoided, it may cause device damage, data loss, device performance degradation, or other unpredictable results. “Caution” does not involve personal injury.
![]()
Supplementary explanation of key information in the text. “Note” is not a safety warning and does not involve personal, device, or environmental harm information.
Revision History
Document Version
Release Date
Revision Description
01
2025-10-17
First official version release.
1 Development Guide
1.1 Overview
The lwIP HTTP Client in BEKEN Controller is named webclient, located in the components/webclient directory. The code is controlled by the feature macro
CONFIG_WEBCLIENT, which is disabled by default.
1.2 Example Code
#include <components/webclient.h> int bk_webclient_get(bk_webclient_input_t *input); //GET request int bk_webclient_post(bk_webclient_input_t *input); //POST request int demo_webclient_get(char *url) //GET request example { int err; if(!url) { err = BK_FAIL; CLI_LOGD( "url is NULL\r\n"); return err; } bk_webclient_input_t config = { .url = url, .header_size = 1024*2, .rx_buffer_size = 1024*4 }; err = bk_webclient_get(&config); if(err == BK_OK) CLI_LOGD("bk_webclient_get ok\r\n"); else CLI_LOGD("bk_webclient_get fail, err:%x\r\n", err); return err; } int demo_webclient_post(char *url, char *post_data) //POST request example { int err; if(!url) { err = BK_FAIL; CLI_LOGD( "url is NULL\r\n"); return err; } if (post_data==NULL) { err = BK_FAIL; CLI_LOGD( "post_data is NULL\r\n"); return err; } bk_webclient_input_t config = { .url = url, .header_size = 1024*2, .rx_buffer_size = 1024*4, .post_data = post_data }; err = bk_webclient_post(&config); if(err == BK_OK) CLI_LOGD("bk_webclient_post ok\r\n"); else CLI_LOGD("bk_webclient_post fail, err:%x\r\n", err); return err; } void cli_webclient_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) //webclient command implementation { int ret = 0; char *msg = NULL; if (argc == 3) { if (strncmp(argv[1], "get", 3) == 0) { CLI_LOGD("starting http(s) get url:%s\n", argv[2]); demo_webclient_get(argv[2]); } else { CLI_LOGE("usage: webclient [get/post].\n"); goto error; } } else if ((argc == 4) && (strncmp(argv[1], "post", 4) == 0)) { CLI_LOGD("starting http(s) post url:%s\n", argv[2]); demo_webclient_post(argv[2], argv[3]); } else { CLI_LOGE("usage: webclient [url].\n"); goto error; } if (!ret) { msg = WIFI_CMD_RSP_SUCCEED; os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); return; } error: msg = WIFI_CMD_RSP_ERROR; os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); return; }
1.3 Usage Example
webclient [ota|get|post] [url] [postdata]
webclient get http://www.baidu.com starting http(s) get url:http://www.baidu.com request header: GET / HTTP/1.1 Host: www.baidu.com User-Agent: BEKEN HTTP Agent response header: HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: no-cache Connection: keep-alive Content-Length: 29506 Content-Type: text/html Date: Tue, 21 Oct 2025 07:06:46 GMT P3p: CP=" OTI DSP COR IVA OUR IND COM " P3p: CP=" OTI DSP COR IVA OUR IND COM " Pragma: no-cache Server: BWS/1.1 Set-Cookie: BAIDUID=A9F4CAE2C24210E1742501480B71218D:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com Set-Cookie: BIDUPSID=A9F4CAE2C24210E1742501480B71218D; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com Set-Cookie: PSTM=1761030406; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com Set-Cookie: BAIDUID=A9F4CAE2C24210E1742501480B71218D:FG=1; max-age=31536000; expires=Wed, 21-Oct-26 07:06:46 GMT; domain=.baidu.com; path=/; version=1; comment=bd Tr_id: pr_0x9afe527f011f1b6d Traceid: 176103040606074982506854824042807921914 Vary: Accept-Encoding X-Ua-Compatible: IE=Edge,chrome=1 X-Xss-Protection: 1;mode=block get position handle response(200). webclient get response data: bk_webclient_get bytes_read:4096 content_pos:4096 bk_webclient_get bytes_read:4096 content_pos:8192 bk_webclient_get bytes_read:4096 content_pos:12288 bk_webclient_get bytes_read:4096 content_pos:16384 bk_webclient_get bytes_read:4096 content_pos:20480 bk_webclient_get bytes_read:4096 content_pos:24576 bk_webclient_get bytes_read:4096 content_pos:28672 bk_webclient_get bytes_read:834 content_pos:29506 k_webclient_get ok $CMDRSP:OK![]()
Using the webclient command requires ensuring that the cli_netif.c module is included in the compilation
Before using the webclient command, ensure that the module is connected to the network
2 Terms
Abbreviation
Term
Description
lwIP
Lightweight TCP/IP Protocol Stack
lwIP is a lightweight open-source TCP/IP protocol stack widely used in embedded systems.
RTOS
Real-Time Operating System
Real-Time Operating System is a real-time operating system used to provide real-time capabilities for embedded systems.
HTTP
Hyper Text Transfer Protocol
Hypertext Transfer Protocol, the most widely used communication protocol between clients and servers on the Internet.
Document Version 01 (2025-10-17) Copyright © Beken Corporation