前一个问题在这里的服务器端文件镖呼吁未来的电子邮件功能是返回一个确认味精或错误。 以下的功能是为“打印”功能工作正常,但对于“res.write”是行不通的。
该server.dart文件:
void handlePost(HttpRequest req) {
HttpResponse res = req.response;
print('${req.method}: ${req.uri.path}');
addCorsHeaders(res);
req.listen((List<int> buffer) {
SendConfirmationNote2Client(String msg) {
print('msg: $msg'); // this is working
res.write(msg); // this looks to be wrong!
res.close();
}
email()
.then(SendConfirmationNote2Client);
}, onError: printError);
}
该client.dart文件是:
void submitFprm(){
request = new HttpRequest();
request.onReadyStateChange.listen(onData);
var url = 'http://127.0.0.1:4040/';
request.open('POST', url);
request.send(JSON.encode(theData));
}
void onData(_) {
if (request.readyState == HttpRequest.DONE && request.status == 200) {
print('request.responseText'); // this is not printing anything!!
server_output.innerHtml=request.responseText; // this working
} else if (request.readyState == HttpRequest.DONE &&
request.status == 0) {
print('no server');
}
}
任何帮助!