客户端异常,我无法打印返回值(请求正文)



好吧,我在这里疯了,在我的flutter应用程序中,我使用这个功能来执行帖子请求:

Future<Map> postRequest(String serviceName, Map<String, dynamic> data) async {
var responseBody = json.decode('{"data": "", "status": "NOK"}');
try {
http.Response response = await http.post(
_urlBase + '$_serverApi$serviceName',
body: jsonEncode(data),
);
if (response.statusCode == 200) {
responseBody = jsonDecode(response.body);
//
// If we receive a new token, let's save it
//
if (responseBody["status"] == "TOKEN") {
await _setMobileToken(responseBody["data"]);
// TODO: rerun the Post request
}
}
} catch (e) {
// An error was received
throw new Exception("POST ERROR");
}
return responseBody;
}

问题是:

  1. 我得到一个ClientException(不是每次(

  2. 在另一个类中,我将这个函数的结果存储在一个变量中,它应该返回一个Future<Map<dynamic, dynamic>>,当我打印它时,它显示:

    I/flutter ( 9001): Instance of 'Future<Map<dynamic, dynamic>>'

但当我直接运行同一个post请求(不使用函数(时,它起作用了,它显示了我正在等待的消息。

注意:在这两种情况下(功能与否(,在服务器端都是一样的。

这是我使用post请求的函数:

void _confirm() {
if (_formKey.currentState.saveAndValidate()) {
print(_formKey.currentState.value);
var v = auth.postRequest("se_connecter", _formKey.currentState.value);
print(v);
} else {
print(_formKey.currentState.value);
print("validation failed");
}
}

对于第二个问题,我只做了以下更改:

void _confirm() async {

var v = await auth.postRequest('se_connecter', _formKey.currentState.value);

是的,这很愚蠢。

对于异常,是ssl加密导致了它,所以我从后端删除了它。