6
考慮下面的僞代碼:如何從HttpRequest.postFormData的catchError的_XMLHttpRequestProgressEvent獲取HTTP響應文本?
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的庫中顯然不存在。
那麼,如何從Web服務器發送的400 BAD REQUEST
響應中獲得響應文本?
我不確定這是否是正確的,因爲我連漸入「那麼」功能。此外,我認爲你的例子已被破壞,因爲onData(_)中的請求是未知的。 – corgrath
我一直在測試這個,看起來大部分2XX都可以,大多數4XX和5XX都會調用'catchError'。 – corgrath
@corgrath看起來你是對的。我現在也測試過了。您需要將請求傳遞給onData - 這是一個CP失敗。嘗試使用error.currentTarget.responseText – markovuksanovic