【问题标题】:Flutter post request parseFlutter 发布请求解析
【发布时间】:2020-10-14 08:52:17
【问题描述】:

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

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您的正文需要为字符串,最好的情况是将您的正文转换为 JSON 字符串,如下所示:

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

    【讨论】:

    • 现在给我一个错误 {"error":{},"jsonrpc":"2.0"} 是来自服务器吗?
    猜你喜欢
    • 2018-10-19
    • 2021-09-23
    • 2014-03-22
    • 2019-10-27
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    相关资源
    最近更新 更多