2013-06-06 21 views

cevap

9

Bir HTTP isteğinin gövdesinde okumak ve faydalı bir şeye dönüştürmek için HttpBodyHandler sınıfını kullanın. Bir form gönderildiğinde, bunu bir Harita'ya dönüştürebilirsiniz.

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 kırma değişim gereği pub paketine http_server taşındı: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/iXbyaSfS2bE – bbs

İlgili konular