firebase cloud function http request body is empty (sending from flutter)

Viewed 551

i'm playing with flutter web (dart) and try to send an http post request with a JSON body to cloud functions. Dart code:

var header = {"Content-Type": "application/json"};
var bodyData = {"text": "something"};
var body = jsonEncode(bodyData);
var response = await http.post(url, headers: header, body: body);

but i got a empty body {} by calling console.log('Request body: ' + JSON.stringify(req.body)); within cloud functions

i've already tried

var header = {"Content-Type": "application/x-www-form-urlencoded"};
var body = 'text=something';
var response = await http.post(url, headers: header, body: body);

calling the same print statement and got (as expected): Request body: {"text":"something"}

it seems to me that there's something wrong with the json encoding?!

0 Answers
Related