DART server to send FUTURE function output back to

2019-07-24 12:06发布

In a previous question here the server side dart file is calling a FUTURE email function that return either a confirmation msg or an error. the function below is working fine for the "print" function, but for the "res.write" is not working.

the server.dart file:

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);
}

the client.dart file is:

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');
  }
}

any help!

1条回答
The star\"
2楼-- · 2019-07-24 12:51

I don't know if it's the correct bug, but you have

print('request.responseText');

But this will print the literal text request.responseText. Should this instead be

print(request.responseText);

?

I would also try running Fiddler to see the exact response coming back from the server; in order to tell if the problem is with the server or client code.

查看更多
登录 后发表回答