网卡 (十二) LWIP 应用层 HTTP

// 地址,方法,recv buff
WebClient("http://ticks.applinzi.com/lwip/get.php?origin_price=2&real_price=6", NULL, &abuf);

1)提取服务器部分 */
2)查询IP */
3)构造访问头 */
4)开始访问 */
	netconn_new(NETCONN_TCP);
	netconn_connect(conn, &server_ip, 80);
	netconn_write(conn, request, strlen((char *)request), NETCONN_COPY);  // request 是 数据内容
	netconn_recv(conn, &inBuf)); // 接收recv 包.
5)分析数据(分析HTTP头,暂时不打算支持301之类的)        */
6)复制正文内容 ,拷贝到第三个参数*/
  • lwip 已经封装好了 http 协议的代码

httpc_get_file_dns
	// 1. 建立 req,设置 recv
	httpc_init_connection
		altcp_recv(req->pcb, httpc_tcp_recv)
	// 2. 连接及发送
	httpc_get_internal_dns
		httpc_get_internal_addr
			altcp_connect

// 1. 建立 req,设置 recv
httpc_init_connection // 构造请求, 设置回调,及初始化参数
	httpc_init_connection_common // recv 参数 是 recv_fn ,http 层 上的 用户数据接收函数 // uri 为 request 中的 uri
		req->recv_fn = recv_fn;
// 2. 连接 httpc_tcp_connected 就是 连接成功后的回调,在该回调中 altcp_write send request
altcp_connect(req->pcb, &req->remote_addr, req->remote_port, httpc_tcp_connected);
	// 用来 connect 
// 3. 发送请求
httpc_tcp_connected
	altcp_write(req->pcb, req->request->payload, req->request->len - 1, TCP_WRITE_FLAG_COPY);

// 4. 接收数据
httpc_tcp_recv
	req->recv_fn(req->callback_arg, pcb, p, r);


altcp_connect 前面的 al 是什么意思?
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值