http - 飞镖中的 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 字符串,它只显示一个空对象。但是,当我使用邮递员进行测试时,它运行良好。
解决方案
尝试将标题“接受”更改为headers: { "Content-Type" : "application/json"}
推荐阅读
- java - 使用spring kafka时如何在生产者中压缩数据
- java - 如何远程连接JDBC
- node.js - MongoDB & NodeJS:不支持选项 [servers] && 不支持选项 [caseTranslate]
- python - 如何通过另一列的值 pandas 聚合 groupBy
- javascript - 反应原生位置相对而不移动其他内容
- macos - NSDateFormatter 从多个区域解析 TimeZone
- django - Django 测试因外键格式错误而无法创建表而无法运行
- linux-kernel - 用户空间代码未调用帧缓冲区写入 cb
- c# - 从 Microsoft.Azure.DocumentDb 迁移到 Microsoft.Azure.Cosmos 以进行数据访问。并非所有选项都可用
- java - Scanner.nextLine() 仅在控制台中抛出 NoLineFound