Reputation: 98
Future<void> _sendData() async {
final url = Uri.https('websitename.tld', 'restricted/login');
try {
final response = await http.post(
url,
headers: {"Content-Type": "application/json"},
body: {
json.encode({
'username': 'UserName',
'userpass': 'UserPaZZw0rd',
})
},
);
} catch (err) {print(err);}
}
causes : flutter: Invalid argument(s): Invalid request body "{{"username":"UserName","userpass":"UserPaZZw0rd"}}". if i make a call without json, code works like a charm. jsonEncode instead of json.encode -> same result.
Any ideas? Thanks!
Upvotes: 1
Views: 3652
Reputation: 5423
Try this.
body: json.encode({
'username': 'UserName',
'userpass': 'UserPaZZw0rd',
}),
Upvotes: 3