我正在使用Flutter Web(飞镖),并尝试将带有JSON正文的http发布请求发送到云函数。飞镖代码:
var header = {"Content-Type": "application/json"};
var bodyData = {"text": "something"};
var body = jsonEncode(bodyData);
var response = await http.post(url, headers: header, body: body);
但是我通过在云函数中调用{}
得到了一个空的身体console.log('Request body: ' + JSON.stringify(req.body));
我已经尝试过
var header = {"Content-Type": "application/x-www-form-urlencoded"};
var body = 'text=something';
var response = await http.post(url, headers: header, body: body);
调用相同的打印语句并得到(如预期的那样):Request body: {"text":"something"}
在我看来json编码有问题吗?!