我正在開發一個顫振專案,我想使用以下代碼將資料添加到 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);
}
}
但是它在我的顫動控制臺中給了我這個錯誤我不知道是什么問題,非常感謝任何幫助:
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>
uj5u.com熱心網友回復:
將正文編碼為 JSON。
body: jsonEncode(sendString),
有關詳細資訊,請參閱向服務器發送資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/477908.html
