我有一个帖子对象。就像下面一样。
{
"facilities": value.join(","),
"start_date": startDate.toString().substring(0, 10),
"end_date": endDate.toString().substring(0, 10),
"over_ratio": false,
"total": true
}
我在正文中发送此对象,但服务器向我发送 404
消息。但是当我编写像 "over_ratio": "false", "total": "true"
这样的 bool
数据时,服务器会理解这个 bool
数据错了。
var response = await http.post(url, body: body);
if (response.statusCode == 200) {
print(response.body);
}
我需要发送此正文 bool
数据,例如:
{
"facilities": value.join(","),
"start_date": startDate.toString().substring(0, 10),
"end_date": endDate.toString().substring(0, 10),
"over_ratio": false,
"total": true
}
我也尝试过,但出现同样的问题:
json.encode({
"facilities": value.join(","),
"start_date": startDate.toString().substring(0, 10),
"end_date": endDate.toString().substring(0, 10),
"over_ratio": false,
"total": true
});
如何正确发送此帖子? 谢谢。
最佳答案
您是否尝试过使用jsonEncode(body)
发布数据
希望它能发挥作用。
关于Post 对象中的 Flutter Bool 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65953268/