我正在使用dart http服务器,并且不确定如何读取http请求中发送的实际内容:“{'text':'一些文本数据。'}”
import 'dart:io';
void main() {
HttpServer.bind('127.0.0.1', 3000).then((server){
server.listen((HttpRequest request) {
print("request made");
request.response.write('''
<html>
<head>
</head>
<body>
<pre>
HELLO:
request info:
method: ${request.method}
uri: ${request.uri}
content length: ${request.contentLength}
content : //HOW DO I GET THIS?
</pre>
<script>
var req = new XMLHttpRequest();
req.open("POST","/a_demonstration");
req.send("{'text':'some text data.'}");
</script>
</body>
</html>
''');
request.response.close();
});
});
}
最佳答案
您可以使用 :
import 'dart:convert' show UTF8;
Future<String> content = UTF8.decodeStream(request);
关于xmlhttprequest - dart,您如何阅读http请求的内容主体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20680073/