无法捕获dioerror [dioerrortype.response]:http状态错误[statusCode]

时间:2020-02-06 08:12:03

标签: node.js json express flutter multer

dioerror [dioerrortype.response]:http状态错误[statusCode]

这是标题部分:

Headers("Authorization": "token", 
        "Content-Type" : "multipart/form-data", 
        "Accept" : "application/json")

这是数据部分:

    try {
      FormData data = FormData.fromMap({
        "username": userName.toString(),
        "name": naMe.toString(),
        "birthday": birthDay.toString(),
        "about": aboutUser.toString(),
        "sender": sendUser.toString(),
        "mobile": userMobile.toString(),
        "avatar": _image != null
            ? await MultipartFile.fromFile(_image.path,
                filename: avatarName.toString())
            : Text('Invalid Avatar'),
      }); 
     }

这是Dio请求/响应部分:

try {
     Dio dio = Dio();
     dio.options.headers['Accept'] = "multipart/form-data";
     dio.options.headers['Authorization'] = "Bearer $token";
     dio.options.headers['Content-Type'] = "application/json";

     var response = await dio.post(url, data: data);
     final res = json.encode(response.data);
     print('$res');
     var responseCode = response.statusCode;
     print('$responseCode');
 }

1 个答案:

答案 0 :(得分:1)

通过使用来编辑catch博客解决了问题

On DioError catch (error) {
   var statusCode = error.response.statusCode;
   Print(statusCode);
}