在上一个问题here中,服务器端dart文件正在调用FUTURE电子邮件函数,该函数返回确认消息或错误。以下功能适用于" print"功能,但对于" 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');
}
}
任何帮助!
答案 0 :(得分:2)
我不知道它是否是正确的错误,但你有
print('request.responseText');
但是这会打印文字request.responseText
。应该是
print(request.responseText);
我也会尝试运行Fiddler来查看从服务器返回的确切响应;为了判断问题是否与服务器或客户端代码有关。