DART server to send FUTURE function output back to the client, how?

人走茶凉 提交于 2019-12-13 02:25:52

问题


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:


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.



来源:https://stackoverflow.com/questions/25410240/dart-server-to-send-future-function-output-back-to-the-client-how

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!