给出以下伪代码:
import "dart:html";
HttpRequest.postFormData(url, data).then((HttpRequest request) {
...
}).catchError((error) {
// How do I get the response text from here?
});
如果 Web 服务器回复
400 BAD REQUEST然后是
catchError将被调用。但是,错误参数的类型是
_XMLHttpRequestProgressEvent这在 Dart 的库中显然不存在。
那么,如何从
400 BAD REQUEST 获取响应文本?从 Web 服务器发送的响应?
请您参考如下方法:
似乎您的错误对象中的目标实际上是您的 HttpRequest。
您可能会发现此链接很有帮助:https://www.dartlang.org/docs/tutorials/forms/#handling-post-requests
你可以这样做:
import "dart:html";
HttpRequest.postFormData(url, data).then((HttpRequest request) {
request.onReadyStateChange.listen((response) => /* do sth with response */);
}).catchError((error) {
print(error.target.responseText); // Current target should be you HttpRequest
});




