Flutter发布请求解析

时间:2020-06-24 06:45:56

标签: flutter dart

我有一个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'类型的子类型 我在做什么错了?

1 个答案:

答案 0 :(得分:0)

您的主体需要为字符串,最好的情况是您可以将主体转换为JSON字符串,如下所示:

  final response = await http.post(url, body: jsonEncode(body), headers: headers);