【问题标题】:API call in Flutter (dart)Flutter 中的 API 调用(飞镖)
【发布时间】:2020-05-01 02:47:29
【问题描述】:

我为我的 Angular 应用程序构建了一个 asp.net web api,它运行良好。我将在 Flutter 中使用相同的 api,但令人惊讶的是,我在 response.body 中没有得到完整的对象。我观察到, response.body 仅包含 1023 个字符。

final response = await http.post(
        apiUrl,
        body: body,
        headers: {
          'Content-Type': 'application/json;',
          'Accept': 'application/json ',
          'Authorization': 'Bearer $_token',
        });
print(response.body) // response.body string length is 1023.

提前感谢您查看我的问题。

【问题讨论】:

  • 您计算了打印的字符串还是打印了字符串长度。仅供参考print 方法有长度限制。如果你有长文本,你应该使用debugPrint。此外,正文中可能存在响应错误
  • print(response.body.length.toString()) 给我 6375 。似乎数据在那里,但打印有一些限制。 @danypata,我尝试使用 debugPrint,但 response.body 仍然限制为 1023 个字符。

标签: api http flutter dart


【解决方案1】:

我有一个类似的问题,似乎 print 有一个字符限制来解锁使用这个更改号码来匹配你的响应字符,或者只是设置一个更高的数字并使用 printWrapped (response.body);而是

void printWrapped(String text) { 
     final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
      pattern.allMatches(text).forEach((match) => print(match.group(0)));
   }

【讨论】:

  • 为我工作。 (只有在每一点内容之前,都会打印I/flutter (17388):。)
猜你喜欢
  • 2020-11-28
  • 2019-03-17
  • 1970-01-01
  • 2023-01-13
  • 2018-03-27
  • 2021-07-31
  • 1970-01-01
  • 2019-05-14
  • 2021-04-02
相关资源
最近更新 更多