【问题标题】:http request return value not getting all data flutterhttp请求返回值没有得到所有数据颤动
【发布时间】:2020-06-15 13:06:23
【问题描述】:

我正在处理 http 请求。突然应我的要求,我得到响应状态代码为“200”,以便我的 api 正在工作..但是,在我的响应正文中,返回不完整。顺便说一下,这是我使用的资源。

  String APILink = "http://10.12.50.46:9191";
  String compressedString2;

 Future<SuccessData> getSession() async {
        http.Response response2=await http.post(
          Uri.encodeFull(APILink+"/Mobile/StartSession"),
          headers:{
            "Auth-Key":"InSys-dev-key-001 ",
          },body:compressedString2,
        );
        print("Compressed JSON:"+compressedString2);
        print(response2.statusCode);
      var dataGather2 = json.decode(response2.body);
      print(response2.body);
    }

这是我对使用 insomnia (Rest API) 的实际反应

这是我在 logcat 上的打印数据:

如果您注意到,我在“ResultSet”上的返回数据不完整.. 其他数据也确实被提取,例如状态、错误消息,并且未查看标签。

【问题讨论】:

    标签: http flutter dart


    【解决方案1】:

    打印功能不会打印所有内容
    您可以看到 Flutter 中的 print() 语句在 Flutter 运行输出中被截断 https://github.com/flutter/flutter/issues/22665

    解决方案 1:
    来自https://github.com/flutter/flutter/issues/22665#issuecomment-580613192
    可以使用下面两个代码sn -p

    void logLongString(String s) {
        if (s == null || s.length <= 0) return;
        const int n = 1000;
        int startIndex = 0;
        int endIndex = n;
        while (startIndex < s.length) {
          if (endIndex > s.length) endIndex = s.length;
          print(s.substring(startIndex, endIndex));
          startIndex += n;
          endIndex = startIndex + n;
        }
    } 
    

    https://github.com/flutter/flutter/issues/22665#issuecomment-513476234

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

    解决方案 2: 在 Android Studio Debug 模式下,在 Variables 窗口中设置断点并复制变量内容

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 2018-05-07
      • 2013-01-17
      • 1970-01-01
      • 2021-07-22
      • 2010-10-16
      • 2020-12-27
      • 1970-01-01
      • 2022-01-04
      相关资源
      最近更新 更多