I am trying to send data of a Student to be added in SQL database by using Go. This is the code :
final jsonbody = jsonEncode(<String, dynamic>{
"StudentId": idController.text,
"StudentName": snController.text,
"FatherName": fnController.text,
"MotherName": mnController.text,
"Cgpa": cgController.text,
"City": ctController.text
});
print(jsonbody);
final responseofAPI = await http.post(
Uri.parse(url),
headers: {'Content-Type': 'application/json'},
body: jsonbody);
print("Code -----> ${responseofAPI.statusCode}");
print(jsonDecode(responseofAPI.body));
print(responseofAPI.body);
And this is the response I am getting :
I/flutter (22041): {"StudentId":"84","StudentName":"Mukul","FatherName":"Mukesh","MotherName":"Swati","Cgpa":"7","City":"Kanpur"}
I/flutter (22041): Code -----> 400
E/flutter (22041): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FormatException: Unexpected end of input (at character 1)
E/flutter (22041):
E/flutter (22041): ^
I have to send the studentId and Cgpa as integer values thats the reason I think the error is coming from.It is now going as string. How can I send integer value from Frontend?
If you commit that the string value from the controller is integer, you can convert the value to integer with int.parse("")
final jsonbody = jsonEncode(<String, dynamic>{
"StudentId": int.parse(idController.text),
"StudentName": snController.text,
"FatherName": fnController.text,
"MotherName": mnController.text,
"Cgpa": int.parse(cgController.text),
"City": ctController.text
});
print(jsonbody);
final responseofAPI = await http.post(
Uri.parse('http://192.168.1.19:8081/everyStudent'),
headers: {'Content-Type': 'application/json'},
body: jsonbody);
print("Code -----> ${responseofAPI.statusCode}");
print(jsonDecode(responseofAPI.body));
print(responseofAPI.body);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments