Sử dụng lớp HttpBodyHandler để đọc trong phần thân của yêu cầu HTTP và biến nó thành nội dung hữu ích. Trong trường hợp gửi biểu mẫu, bạn có thể chuyển đổi nó thành Bản đồ.
import 'dart:io';
main() {
HttpServer.bind('0.0.0.0', 8888).then((HttpServer server) {
server.listen((HttpRequest req) {
if (req.uri.path == '/submit' && req.method == 'POST') {
print('received submit');
HttpBodyHandler.processRequest(req).then((HttpBody body) {
print(body.body.runtimeType); // Map
req.response.headers.add('Access-Control-Allow-Origin', '*');
req.response.headers.add('Content-Type', 'text/plain');
req.response.statusCode = 201;
req.response.write(body.body.toString());
req.response.close();
})
.catchError((e) => print('Error parsing body: $e'));
}
});
});
}
Nguồn
2013-06-06 03:14:14
HttpBodyHandler chuyển sang gói quán rượu http_server theo sự thay đổi phá vỡ: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/iXbyaSfS2bE – bbs