我正在处理 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);
}
Run Code Online (Sandbox Code Playgroud)
这是我使用 insomnia (Rest API) 时的实际反应
这是我在 logcat 上的打印数据:
如果您注意到,我在“ResultSet”上的返回数据不完整。其他数据也确实会被获取,例如状态、错误消息,并且标签不会被查看。
打印函数不会打印所有内容
您可以看到Flutter 中的 print() 语句在 flutter run 输出中被截断
https://github.com/flutter/flutter/issues/22665
解决方案1:
来自https://github.com/flutter/flutter/issues/22665#issuecomment-580613192
您可以使用以下两个代码片段
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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)));
}
Run Code Online (Sandbox Code Playgroud)
解决方案2:在Android Studio Debug模式下,设置断点并在Variables窗口中复制变量内容

| 归档时间: |
|
| 查看次数: |
2708 次 |
| 最近记录: |