Dart – print all response headers

Issue

My Dart code send a form via post method to my GAE python server. I would like to see all headers return by the server in the response. but I can’t perform that. Could you help?

    void _httpRequest(url, datas){
HttpRequest request = new HttpRequest() 
  ..open("POST", url, async: true)
  ..setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  ..responseType = "";

// add an event handler that is called when the request finishes
request.onReadyStateChange.listen((_) {
  if (request.status == 200) {
      _onSuccess(request.responseText);
  }else{
      _handleTheError(request.responseText);
  }
});

   request.send(datas);
}

void _onSuccess(msg){
    print("success : $msg");
}

void _handleTheError(msg){
    print("error : $msg");
}

Solution

request.responseHeaders.forEach((k, v) {
  print('Header: $k, value: $v');
});

Answered By – Günter Zöchbauer

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *