flutter - GET 请求在 Dart 中为 http 包 Flutter 显示“406 - Not Acceptable”
问题描述
我正在请求以下获取请求,但收到“406 - 不可接受”响应。在这里我附上了请求代码:
final Map<String, String> tokenData = {"Authorization": token};
var response = await http.get(url, headers: tokenData);
if (response.statusCode == 200) {
var jsonResponse = convert.jsonDecode(response.body);
var itemCount = jsonResponse['totalItems'];
print('Number of books about http: $itemCount.');
} else {
print('Request failed with status: ${response.statusCode}.');
print('Request failed with reason: ${response.reasonPhrase}.');
}
解决方案
更改您的tokenData 如下:
final Map<String, String> tokenData = {
'Authorization': token
'Content-type': 'application/json',
'Accept': 'application/json',
};
如果您将 JSON 作为响应,它将起作用。
推荐阅读
- python - 发生异常时如何跳过for循环中的迭代Python
- line - 是否可以在同一行的 2 个输出之间接受用户输入
- docker - 多阶段构建只是加载最后一部分?
- office365 - 如果用户必须使用辅助服务凭据登录,我们是否允许将 Excel JS 加载项发布到 Microsoft App Source?
- symfony - 全局覆盖控制台样式的最简洁方法
- java - Android ImageButton 在小屏幕尺寸下调整大小
- junit5 - pact-jvm-provider - JUnit5 Spring - 无法添加授权标头
- python - Python psycopg2 SELECT 返回无
- c++ - boost::geometry::intersection 返回什么
- visual-studio - 如何使用运行代码选项在 vs 代码中运行 python