http请求中的Dart字符编码

der*_*can 5 character-encoding dart flutter

刚刚学习Flutter,在尝试调用API时遇到了这个问题:

\n
final response = await http.get(\n  Uri.https(apiBaseUrl, apiBaseEndpoint + "/tasks"),\n  headers: {\n    "Authorization": "Bearer " + apiKey,\n  },\n);\n\nprint(response.body);\n
Run Code Online (Sandbox Code Playgroud)\n

我的部分回复包含\xc3\x84\xc2\xb0ftar并且应该是\xc4\xb0ftar。我想这是一些编码问题?curl给我返回带有正确字符的响应。

\n

基本上:这是文本编码问题吗?如果是这样,我该如何解决我的请求?

\n

der*_*can 17

好吧,在对http 文档进行了更多的挖掘之后,我意识到需要更改的不是我如何发出请求,而是我如何处理响应。我在做

final decodedJson = json.decode(response.body);

我应该这样做:

final decodedJson = json.decode(utf8.decode(response.bodyBytes));

这已经解决了我的问题!