给出以下伪代码:
import "dart:html";
HttpRequest.postFormData(url, data).then((HttpRequest request) {
...
}).catchError((error) {
// How do I get the response text from here?
});
Run Code Online (Sandbox Code Playgroud)
如果Web服务器回复a 400 BAD REQUEST,catchError则将调用.但是,error参数的类型_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
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1786 次 |
| 最近记录: |