简体   繁体   中英

flutter send data to server (statusCode 500)

I am new to flutter and am trying to send data to the server. I followed a tutorial , but it did not work it give me a status code 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);

}

在此处输入图像描述

You do not correctly pass the body. You need to jsonEncode your key-value pair like this:

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" 
    });

Please carefully look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM