You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter+Rust Web应用创建用户时POST请求体无法被afire接收

Flutter与Rust(afire) POST请求体丢失问题

在用Flutter与Rust的afire框架开发Web应用时,创建新用户的POST请求环节出现异常:

Flutter端请求代码

Future<http.Response> createUserRequest(String email, String name, String forename, String password) {
  // start by hashing the pass
  var hashPass = sha256.convert(utf8.encode(password));
  // post the request
  return http.post(
    Uri.parse('http://$waterFlowServerAddress/main/auth/create_user'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: json.encode(<String, String>{
      'email': email,
      'name': name,
      'forename': forename,
      'pwhash': hashPass.toString(),
    }),
  );
}

Rust(afire)端路由代码

server.route(Method::POST, "/main/auth/create_user/", |req| {
    println!("{:?}", req);
});

排查情况

  • 打印服务端请求对象,发现body字段为空,raw_data字段仅包含请求头内容
  • 通过Wireshark捕获请求,确认Flutter发送的请求确实带有请求体,初步判断问题出在服务端
  • 使用Python发送POST请求进行测试,服务端能正常读取到请求体,对比两者请求头未发现明显差异
  • 克隆afire库源码调试后发现,框架从TcpStream中仅读取到了请求头部分,推测是afire未检查请求是否完整导致的问题

内容的提问来源于stack exchange,提问作者LucioleMaléfique

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:05:46