Edit: After hours of work, i might because when i send "content-type": "application/json", it send "application/json; charset=utf-8" to server. How to remove ; charset=utf-8 from header?
Edit2: The problem is because flutter send charset=utf-8 in Content-type. I fix by contact my backend developer to allow "application/json; charset=utf-8" in Content-type header
I send post request to server, return error
{"error":"true","code":"30","message":" Data must JSON"}
This is my code:
Future<void> _getToken() async {
final url =
Uri.parse("http://apimobile.xxxx.co.id/Apimobile/auth");
final Map<String, String> data = {
"username": "xxxx",
"password": "xxxx"
};
try {
final response = await http.post(url,
headers: {
"Content-Type": "application/json",
"accept": "application/json",
},
body: jsonEncode(data));
print(response.body);
final responseData = jsonDecode(response.body);
_token = responseData["message"];
} catch (error) {
throw error;
}
}
Is there something wrong in my code?
The API work on Postman, ThunderClient VS Code, and React Native
Thanks for your help