vsf_httpc更新,支持POST等各种操作

[复制链接]
850|1
手机看帖
扫描二维码
随时随地手机跟帖
vsfopen|  楼主 | 2018-8-5 11:24 | 显示全部楼层 |阅读模式
ST, pc, POS, TVS, tv
本帖最后由 vsfopen 于 2018-8-5 12:26 编辑

坐标:https://gitee.com/versaloon/vsf_open/blob/master/vsf/component/tcpip/proto/http/vsfip_httpc.c

使用PT协程的方式实现,接口如下:
1. vsf_err_t vsfip_httpc_connect(struct vsfsm_pt_t *pt, vsfsm_evt_t evt, const char *host);
host可以是"www.baidu.com"这样的域名,也可以是"123.456.789.1"这样的IP地址。
pt->user_data必须为struct vsfip_httpc_t实例,host的端口由httpc->port决定。
2. vsf_err_t vsfip_httpc_disconnect(struct vsfsm_pt_t *pt, vsfsm_evt_t evt);
断开之前的连接。
3. vsf_err_t vsfip_httpc_get(struct vsfsm_pt_t *pt, vsfsm_evt_t evt, const char *path, struct vsf_stream_t *rx_stream);
发送GET到指定的path,接收到的数据会写到rx_stream中,自带流控。
4. vsf_err_t vsfip_httcp_post(struct vsfsm_pt_t *pt, vsfsm_evt_t evt, const char *path, const char *content_type, uint32_t content_length, struct vsf_stream_t *tx_stream, struct vsf_stream_t *rx_stream);
发送POST到指定的path,数据类型和长度由content_type和content_length指定,发送数据位于tx_stream中(支持流控)。如果主机应答中带数据,并且rx_stream不为空,则会吧应答数据写入到rx_stream,同样带流控;否则丢弃应答里的数据。
5. vsf_err_t vsfip_httpc_run(struct vsfsm_pt_t *pt, vsfsm_evt_t evt, const char *verb, const char *path, const char *content_type, uint32_t content_length, struct vsf_stream_t *tx_stream, struct vsf_stream_t *rx_stream);
vsfip_httpc_get和vsfip_httpc_post最终都是调用vsfip_httpc_run。由用户指定verb(比如"GET","DELETE"等等),如果tx_stream不为空,则需要发送数据,类型和长度由content_type以及content_length决定,如果应答中有数据,操作方式同vsfip_httpc_post。

使用特权

评论回复

相关帖子

shanshan2017| | 2020-2-22 19:58 | 显示全部楼层
呵呵,明白了O(∩_∩)O~

使用特权

评论回复
发新帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

89

主题

324

帖子

8

粉丝