2013-06-06 33 views

Trả lời

9

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')); 
     } 
    }); 
    }); 
} 
+1

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

Các vấn đề liên quan