6
Dart로 HTTP 서버를 작성 했으므로 양식 제출을 구문 분석하려고합니다. 특히, HTML 양식의 x-url-form-encoded 양식 제출을 처리하려고합니다. dart:io
라이브러리로 어떻게이 작업을 수행 할 수 있습니까?Dart로 양식 제출을 구문 분석하려면 어떻게해야합니까?
Dart로 HTTP 서버를 작성 했으므로 양식 제출을 구문 분석하려고합니다. 특히, HTML 양식의 x-url-form-encoded 양식 제출을 처리하려고합니다. dart:io
라이브러리로 어떻게이 작업을 수행 할 수 있습니까?Dart로 양식 제출을 구문 분석하려면 어떻게해야합니까?
HTTP 요청 본문을 읽고 유용하게 사용할 수 있도록 HttpBodyHandler 클래스를 사용하십시오. 양식 제출의 경우 맵으로 변환 할 수 있습니다.
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'));
}
});
});
}
HttpBodyHandler은 주요 변경에 따라 술집 패키지 http_server로 이동 : https://groups.google.com/a/dartlang.org/forum/#!topic/misc/iXbyaSfS2bE – bbs