我正在尝试使用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 参数体有疑问。
这里是我的带有 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] 删除。
我来说两句