我一直在尝试处理渡槽中的帖子请求。阅读文档后,这就是我能够想出的 channel.dart
router
.route("/chat")//"/chat/[:id]")
.link(() => ChatController());
聊天控制器.dart
> import 'package:web_api/web_api.dart';
class ChatController extends ResourceController{
@Operation.get('id')
Future<Response> getProjectById(@Bind.path("id") int id) async {
// GET /chat/:id
print(id);
//return Response.ok({"key": "value"});
}
@Operation.post()
Future<Response> createChat(@Bind.body() Chat chat) async {
// POST /project
print("post");
final Map<String, dynamic> body = await request.body.decode();
final name =body['name'] as String;
print(" 1) name ==> $name");
//return Response.ok({"key": "value"});
}
}
class Chat extends Serializable{
int id;
String name;
@override
void readFromMap(Map<String, dynamic> map) {
id = map['id'] as int;
name = map['name'] as String;
}
@override
Map<String, dynamic> asMap() {
return {
'id': id,
'name': name
};
}
}
最后是 html 模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="http://127.0.0.1:8888/chat" method="POST">
<input id="id" name="id">
<input id="name" name="name">
<button type="submit">Submit</button>
</form>
</body>
</html>
aquaduct 不提供 html 模板。这是一个不同的位置。当我提交表单时,我的控制台日志。
[INFO] aqueduct: Server aqueduct/2 started.
[INFO] aqueduct: POST /chat 15ms 415
为什么我看不到正文内容,我怎么能看到正文(表单值)