Dart中的HTTP.put方法

时间:2018-10-10 06:54:43

标签: http dart flutter put

我一直在尝试使用dart http包通过flutter框架发送 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字符串,它仅显示一个空对象。但是,当我与邮递员进行测试时,效果很好。

1 个答案:

答案 0 :(得分:0)

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