为什么我的 Flutter 认证 response.statusCode 总是 200?

图因

我正在尝试使用HTTP POST实现简单的登录身份验证,但我response.statusCode == 200总是这样做,它允许我转到下一页。

这是我的简单身份验证功能:

Future<void> login() async {
if (passwordontroller.text.isNotEmpty && emailController.text.isNotEmpty) {
  var response = await http.post(Uri.parse("http://medbo.digitalicon.in/api/medboapi/login"),
      body: ({
        'LoginId': emailController.text,
        'Password': passwordontroller.text
      }));
  if (response.statusCode == 200) {
    print("Correct");
    Navigator.push(context, MaterialPageRoute(builder: (context)=> Second()));
  } else {
    print("Wronggooooooooooooooooooooooooooo");
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: Text("Invalid credentials")));
  }
} else {
  ScaffoldMessenger.of(context)
      .showSnackBar(SnackBar(content: Text("Blank field is not allowed")));
}

}

我对我的 Json 参数体有疑问。

这是我的 Json 响应: 在此处输入图片说明

这里是我的带有 emailController 和 passwordController 的 TextFormField:

 TextFormField(
            controller:
                emailController, //==========================================
            decoration: InputDecoration(
                labelText: "Email",
                border: OutlineInputBorder(),
                suffixIcon: Icon(Icons.email)),
          ),
          SizedBox(
            height: 10,
          ),
          TextFormField(
            controller:
                passwordontroller, //=========================================
            obscureText: true,
            decoration: InputDecoration(
                labelText: "Password",
                border: OutlineInputBorder(),
                suffixIcon: Icon(Icons.password)),
          ),
          SizedBox(
            height: 45,
          ),
          OutlinedButton.icon(
              onPressed: () {
                login();
              },
案件

statusCode 200 仅表示您从服务器获得了成功的响应。这很可能不会说明您发送的数据的实际身份验证状态,您可以“最有可能”在响应正文中找到 。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章