【问题标题】:Unable to catch dioerror [dioerrortype.response]: http status error [statusCode]无法捕获 dioerror [dioerrortype.response]:http 状态错误 [statusCode]
【发布时间】:2020-05-22 05:24:05
【问题描述】:

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');
 }

【问题讨论】:

  • 欢迎您!快速建议:如果您将标题更改为问题并显示您的代码以及错误,您将获得更多人的帮助。
  • 在第一个块中,您使用多部分形式;在第二个 JSON 中?哪个是对的?您没有显示 data 是什么。您可以使用 Postman 或类似工具连接到服务器吗?
  • 在邮递员中我得到了正确的答复。 & 在邮递员中,它们只有两个标题,一个是 Authorization,第二个是 Content-Type:application/json
  • 多部分标题是否会发生这种情况......??
  • 问题解决了。

标签: node.js json express flutter multer


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-08-31
    • 1970-01-01
    • 2022-11-29
    • 2022-12-23
    • 2020-03-22
    • 2020-04-18
    • 2023-03-25
    • 1970-01-01
    • 2021-08-19
    相关资源
    最近更新 更多