【问题标题】:flutter send data to server (statusCode 500)颤振发送数据到服务器(statusCode 500)
【发布时间】:2021-01-18 07:39:24
【问题描述】:

我是 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);

}

【问题讨论】:

  • 我投票结束这个问题,因为它与密码长度不足有关。

标签: flutter http


【解决方案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

【讨论】:

  • 对不起,我忘了放它,但我已经使用它但它不起作用,同样发生状态码 500
  • 你在Postman上成功拿到结果了吗?
  • 邮递员的 HTTP 状态码是 200 吗?首先,您需要在 Postman 上提供该信息。如果 Postman 也是 500,则可能是与您的服务器有关的另一个问题。
  • 您还需要添加标题数据。我编辑了问题。
  • 我用它试试,不用它也一样
猜你喜欢
  • 2020-04-18
  • 2020-06-14
  • 2020-08-16
  • 2021-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
相关资源
最近更新 更多