首页 > 解决方案 > 在 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);
}

我编辑了出现异常的屏幕截图:

在此处输入图像描述

标签: jsondatabaseapiflutterexception

解决方案


推荐阅读