How to get HTTP response text from HttpRequest.postFormData catchError _XMLHttpRequestProgressEvent?

Given the following pseudo code:

import "dart:html"; HttpRequest.postFormData(url, data).then((HttpRequest request) { ... }).catchError((error) { // How do I get the response text from here? }); 

If the web server responds with 400 BAD REQUEST , then catchError will be catchError . However, the error parameter is of type _XMLHttpRequestProgressEvent , which apparently does not exist in the Dart library.

So, how to get the response text from the 400 BAD REQUEST response sent from the web server?

+6
source share
1 answer

It seems that the target in your error object is your HttpRequest.

You may find this link useful: https://www.dartlang.org/docs/tutorials/forms/#handling-post-requests

You can do something like:

 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 }); 
+6
source

All Articles