首页 > 解决方案 > 飞镖中的 HTTP.put 方法

问题描述

我一直在尝试使用 dart http 包通过颤振框架发送一个http put请求。这是我的 json 字符串

var jsonMap = {

  'status': '1',
    'time': new DateTime.now().toIso8601String(),
    'teamMemId': '7',
    'empId': "953280086v",
    'comId': 2.toString(),
    'description': "j new attendence",
    'effDate': date.toIso8601String()


};

和http请求方法

String jsonStr = jsonEncode(jsonMap);
print(jsonMap);
http.put(Uri.encodeFull(url), body: jsonStr , headers: { "Accept" : "application/json"}).then((result) {
  print(result.statusCode);
  print(result.body);
});

错误是 node.js 文件没有捕获 json 字符串,它只显示一个空对象。但是,当我使用邮递员进行测试时,它运行良好。

标签: httpdartflutterput

解决方案


尝试将标题“接受”更改为headers: { "Content-Type" : "application/json"}


推荐阅读