我正在尝试使用 Post 方法创建登录系统,但出现错误
我用邮递员对其进行了测试,使用它就像一个魅力。
我尝试了其他事情,但无法解决此错误。如果这里有人可以解决我的问题,将不胜感激。
飞镖代码
Future userLogin() async {
// var data = {'username': "admin", 'password': "admin12345"};
var response = await http
.post(loginAPI, body: {'username': 'admin', 'password': 'admin12345'});
var message = json.decode(response.body);
print(message);
}
我用来支持数据的登录脚本。
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$username = $_POST['username'];
$password = $_POST['password'];
$Sql_Query = "select * from UserDetails where username = '$username' and password = '$password'";
$check = mysqli_fetch_array(mysqli_query($con,$Sql_Query));
if(isset($check)){
echo "Success";
}
else{
echo "Invalid";
}
}else{
echo "Again";
}
mysqli_close($con);
?>
每当我尝试登录时,我都会收到此错误。
E/flutter ( 3935): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter ( 3935): Success
E/flutter ( 3935): ^
E/flutter ( 3935):
E/flutter ( 3935): #0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1404:5)
E/flutter ( 3935): #1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1271:9)
E/flutter ( 3935): #2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:936:22)
E/flutter ( 3935): #3 _parseJson (dart:convert-patch/convert_patch.dart:40:10)
E/flutter ( 3935): #4 JsonDecoder.convert (dart:convert/json.dart:505:36)
E/flutter ( 3935): #5 JsonCodec.decode (dart:convert/json.dart:156:41)
E/flutter ( 3935): #6 _BodyContainerState.userLogin
package:wish_coin/Screens/LoginScreen.dart:104
E/flutter ( 3935): <asynchronous suspension>
E/flutter ( 3935): #7 _BodyContainerState.loginButtonPressed.<anonymous closure>