json - 在 api put 调用上调用 null 的长度抖动异常
问题描述
我试图在邮递员软件中调用 put API,它在那里工作。我在 Authorization 选项卡中使用 Bearer Token 发送数据。但是当我在 Flutter 中使用 HTTP 函数尝试相同的事情时,捕获到一个异常,说“getter“length”被调用为 null”,因为我没有在数据中使用任何长度或列表。
Future<void>EditProfile(PublisherEdit p)async{
// http.Response response;
print("Hello");
// print(p.username+p.phone+p.content_type+p.pricesPeriod+p.pricesAmount);
// print(userdata.user.token);
try{
// print("hllllo");
dynamic response = await http.put("http://newsbagserver-env.eba-ymb65tjc.us-west-2.elasticbeanstalk.com/api/publishers/5fce6bbe09f4e82b6b2f9bf9",
body: {
"username" : "abc",
"phone" : "abc",
"photo" : p.photo,
"content_type" : "abc",//p.content_type,
"frequency":"abc",
"bank":"abc",
"account_name":"abc",
"account _number":"abc",
},
headers: {
// 'Content-Type': 'application/form-data',
// 'Accept': 'application/json',
HttpHeaders.authorizationHeader: userdata.user.token,
},
);
print("hel"+response.body);
}catch(e){
print("Hello1");
print("error" + e.toString());
}
// print("hel"+response.body);
}
我编辑了出现异常的屏幕截图:
解决方案
推荐阅读
- node.js - 服务器选择在 30000 毫秒后超时堆栈:MongooseServerSelectionError:服务器选择在 30000 毫秒后超时
- python - 使用python在kivy上打开相机on_pressed
- entity-framework - 如何在 EF 存储库模式中使用 2 个表达式
- jsonpath - 使用 JSONPath 将过滤器应用于对象内的实体
- sql - SQL Server - 加入问题
- java - word.toUpperCase().chars() 或 word.chars().map(Chars::toUpperCase) 哪个更好?
- flutter - Flutter 画一个半圆(半圆)但底部没有空格
- mysql - 在sql中的一张表之后显示表
- php - PHP zip getStream() 在在线服务器中总是返回 false。本地效果很好
- swift - 动作按钮的 Swift UNNotificationRequest 标识符点击了本地通知