dart 中的 HTTP.put 方法

din*_*dhi 2 http put dart flutter

我一直在尝试使用 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()


};
Run Code Online (Sandbox Code Playgroud)

和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);
});
Run Code Online (Sandbox Code Playgroud)

错误是node.js 文件没有捕获json 字符串,它只显示一个空对象。然而,当我与邮递员一起测试时,效果很好。

小智 6

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