颤动向服务器发送数据(状态代码 500)

时间:2021-01-18 07:39:24

标签: flutter http

我是 flutter 的新手,正在尝试将数据发送到服务器。我关注了 tutorial,但它不起作用,它给了我一个状态代码 500:

void signUp() async {
http.Response response = await http.post(
    "https://my-shop-server.herokuapp.com/api/v1/users/signup",

    body:jsonEncode(<String, String>{
    "name" :"test" ,
    "email" : "test180@gmail.com" ,
    "password" : "qwert" ,
    "passwordConfirm" : "qwert"
    })
);


print(response.body);
print(response.statusCode);

}

enter image description here

1 个答案:

答案 0 :(得分:-1)

你没有正确地传递身体。您需要像这样对您的键值对进行 jsonEncode:

http.Response response = await http.post(
    "https://my-shop-server.herokuapp.com/api/v1/users/signup",
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },

body:jsonEncode(<String, String>{
  "name" :"test" ,
  "email" : "test180@gmail.com" ,
  "password" : "qwert" ,
  "passwordConfirm" : "qwert" 
    });

请仔细查看here

相关问题