i try to send post request in flutter app like
static Future<List<dynamic>?> postData(data) async {
var body = json.encode(data);
Map<String, String> headers = {"Content-Type": "application/json"};
var url = Uri.http(Config.api, Config.endPoint);
var response = await client.post(url, headers: headers, body: body);
if (response.statusCode == 201) {
var data = jsonDecode(response.body);
return data;
}
return null;
}
this is data was sent
Map data = {
'database': 'school_control_ykt',
'table': 'tablets_helper',
'place': place,
'reason': reason,
'teacher': teacher,
'name': name,
'id_group': id_group
};
postData(data);
but in server side (php) $_POST
are empty
i wanna know why $_POST
are empty when a send the request in flutter app but in Postman request is send successfully and $_POST
have data
enter image description here
Use MultipartRequest as API expect multipart/form-data
. Something like this:
var request = MultipartRequest('POST', uri)
..fields = data
var response = await request.send();