Post 数据到 json api 使用 flutter
Post data to json api using flutter
我正在开发一个 flutter 项目,我想使用以下代码向 json api 添加数据:
save() async {
try{
var sendString =
{
'userId': userId,
'userEmail': userEmail,
};
final response = await http.post(
Uri.parse('http://localhost:5000/createapp'),
headers: <String, String>{
"ContentType": 'application/json; charset=UTF-8',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
"Access-Control-Allow-Methods": "POST, OPTIONS",
},
body: sendString,
);
print(response.body);
}catch(e){
print(e);
}
}
但是它在我的 flutter 控制台中给了我这个错误我不知道是什么问题,非常感谢任何帮助:
Posting data...
<!doctype html>
<html lang=en>
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
将正文编码为 JSON。
body: jsonEncode(sendString),
我正在开发一个 flutter 项目,我想使用以下代码向 json api 添加数据:
save() async {
try{
var sendString =
{
'userId': userId,
'userEmail': userEmail,
};
final response = await http.post(
Uri.parse('http://localhost:5000/createapp'),
headers: <String, String>{
"ContentType": 'application/json; charset=UTF-8',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
"Access-Control-Allow-Methods": "POST, OPTIONS",
},
body: sendString,
);
print(response.body);
}catch(e){
print(e);
}
}
但是它在我的 flutter 控制台中给了我这个错误我不知道是什么问题,非常感谢任何帮助:
Posting data...
<!doctype html>
<html lang=en>
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
将正文编码为 JSON。
body: jsonEncode(sendString),