我正在使用 flutter 创建一个应用程序,在此我创建一个发布请求,然后将响应读取为字符串(稍后转换为 json)。
Future<String> post([String url = "https://example.com/get-new"]) async {
return await http.post(Uri.encodeFull(url),
headers: {"Accept": "application/json"}).then((http.Response response) {
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode > 400) {
throw new Exception("Error while fetching data");
}
return response.body;
});
}
post().then((val){
print(val);
});
它工作正常并得到响应,但正如我的问题所说,响应仅限于 1023 个字符。我和邮递员检查了一下,发现回复按需要正确发送了。
如果有人能帮助我解决这个问题,那就太好了。
提前致谢
Dart
print()
的字符数限制约为 1024 个字符。解决此问题的方法是利用 wrapWidth
的 debugPrint()
参数。设置此参数后,一旦命中该值,后续字符将换行打印。
post().then((val){
debugPrint(val, wrapWidth: 1000);
});