flutter - Flutter 发布请求解析
问题描述
我有一个 POST 请求:
static String url = 'https://checkout.test.paycom.com/api';
static Map<String, String> headers = {
'Host': 'checkout.test.paycom.com',
'X-Auth': '1234',
'Cache-Control': 'no-cache'
};
Future<Map<String, dynamic>> createCard() async {
try {
Map<String, dynamic> body = {
"id": '123',
"method": "receipts.create",
"params": {
"amount": '2500',
"account": {"order_id": '106'}
}
}
final response = await http.post(url, body: body, headers: headers);
print(response.body);
} catch (e) {
print(e.toString());
}
return null;
}
并给出错误类型 '_InternalLinkedHashMap<String, Object>' is not a subtype of type 'String' in type cast 我做错了什么?
解决方案
你的身体需要作为字符串,最好的情况是你可以将你的身体转换为 JSON 字符串,如下所示:
final response = await http.post(url, body: jsonEncode(body), headers: headers);
推荐阅读
- javascript - 由于 CORS 政策,Google Sheets JSON API 未能获取
- javascript - TypeError:无法读取未定义的属性“长度” - JavaScript 和 HTML
- sql - Laravel where 子句基于数据库中值的条件
- xml - 使用 XSLT 2.0 按日期降序对 XML 节点进行排序
- python-3.x - 在 Mac 上安装 Google Football 时出现错误
- php - Yourls:如何使插件接受除 http 或 https 以外的其他方案中的 url
- mongodb - 如何在 mongodb 中按地理空间属性分组?
- c - 为什么strcat的结果是空的
- typescript - 回调函数中对象的通用键名
- vue.js - 在 vue-i18n 翻译中转义管道