# HTTPClient **Repository Path**: hbqs/HTTPClient ## Basic Information - **Project Name**: HTTPClient - **Description**: HTTPClient组件提供了可用于嵌入式设备上的http客户端应用实现,同时支持https。 - **Primary Language**: C - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2022-04-24 - **Last Updated**: 2022-04-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HTTPClient组件 #### 1. 简介 HTTP(Hypertext Transfer Protocol)协议,即超文本传输协议,HTTP是一个基于TCP/IP通信协议来传递数据(HTML 文件, 图片文件, 查询结果等)。HTTP协议实现主要运用在浏览器访问网页,根据请求的内容,服务器返回相应的请求内容为B/S模式,而嵌入式操作系统中主要运用的式C/S模式,即客户端与服务器的方式,通过系统客户端构造请求的消息,访问服务器,然后服务器返回相应的内容.HTTP协议工作于C/S(客户端/服务器)架构之上。HTTP协议协议最新版本是 HTTP 2.0,目前是用最广泛的是 HTTP 1.1。因为HTTP 1.1已经能满足我们基本需求了。HTTP协议目前有两种传输模式分别是HTTP和HTTPS,其中HTTPS = HTTP + SSL(或TLS)。HTTP传输方式访问的服务器默认端口为80端口。HTTPS传输方式访问的服务器默认端口为443。 #### 2. 使用方法 ##### 2.1 menuconfig配置 使用menuconfig,开启HTTPClient组件 ```c (Top) → Components→ Network→ Protocols→ Httpclient [*] Enable Httpclient [*] Enable Httpclient TLS encrypt [*] Enable HTTPCLIENT sample (5000) HTTP SET RECV TIMEOUT MS (NEW) ``` - 其中HTTPClient组件配置如上图所示,具体如下: - 使能HTTPClient组件,启用HTTPClient相关功能。 - 使能HTTPClient加密,启用HTTPS相关功能。 - 使能HTTPClient实例,可以在shell组件开启下,运行对应的sample相关shell命令。 - HTTP设置select查询数据超时,在网络状况不好的情况下可以修改其默认值。 修改运行shell命令需要修改栈大小从2048->7168 ```c (Top) → Components→ Shell k s -*- Enable shell (tshell) The shell task name (20) The priority level value of shell task (7168) The stack size for shell task [*] Enable command history feature (5) The command history line number [*] Keep description in symbol table [ ] Disable the echo mode in default (80) The command line size for shell (10) The command arg num for shell [ ] Shell support authentication ``` 在运行加密组件是需要修改最大分片长度从3584->16384 ```c (Top) → Components→ Security→ mbedtls: An portable and flexible SSL/TLS library Select Root Certificate ---> [*] Store the AES tables in ROM (NEW) (2) Maximum window size used (NEW) (16384) Maxium fragment length in bytes [ ] Enable a mbedtls client example (NEW) (1024) Maximum number of bytes for usable MPIs (NEW) (32) The key size used by the cipher (NEW) [ ] Enable Debug log output (NEW) version (v2.7.10) ---> ``` #### 3. 组件接口概述 ##### API列表 | **接口** | **说明** | | :----------------- | :--------------------------------------------------- | | http_client_get | HTTP组件用于客户端访问服务器网站或者下载文件 | | http_client_post | HTTP组件用于客户端访问服务器网站上传数据或者上传文件 | | http_client_put | HTTP组件用户客户端访问服务器指定位置上传文件 | | http_client_head | HTTP组件用于客户端访问服务器下载不含响应信息消息 | | http_client_delete | HTTP组件用于客户端访问服务器删除信息 | | http_client_conn | HTTP组件用于客户端连接服务器 | | http_client_send | HTTP组件用于客户端发送消息给服务器 | | http_client_recv | HTTP组件用于客户端接收服务器接受的信息 | #### 4. 使用实例 ##### 4.1 shell命令使用 HTTP加密get测试命令: http_get_sample 默认会访问url:https://open.iot.10086.cn/ HTTP非加密get测试命令: 可以通过手动输入网址测试 http_get_sample+url,例如 ```c http_get_sample http://www.10086.cn/index/sc/index_280_280.html ``` HTTP加密post测试命令: http_post_sample 默认会访问url: https://10.15.17.39:28443/server/echo http非加密post测试命令: 可以通过手动输入网址测试 http_post_sample+url,例如 ```c http_post_sample http://121.89.166.244/server/echo ``` #### 5. 常见问题 ##### 5.1 运行默认的shell命令没有反应 - 可能代码中维护的服务器网址有问题,可以更改其它网址尝试。 - 可以尝试检查网络是否正常通信,lwip_ifconfig命令查看是否分配了ip地址。 ##### 5.2 运行shell命令返回失败 - 请查看错误码 根据错误码判断失败原因。