I'm trying to get the email and password from a flutter app using PHP but for some reason i'm getting null results, any idea how I can do it?
Seems that the PHP code actually works fine if the username and password are in the URL itself, however, does not work if I try to follow the example below.
PHP:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET');
echo $email = $_GET["email"];
echo $password = $_GET["password"];
Flutter:
Future<void> login(String email, String password) async {
final url = Uri.parse(
'example.com/file.php');
final response = await http.post(
url,
body: json.encode(
{
'email': email,
'password': password,
},
),
);
}
CodePudding user response:
I'm not familiar with Flutter, put it seems you are posting (POST) your vars. So it should mabe be:
echo $email = $_POST["email"];
echo $password = $_POST["password"];
Or it is in the body of the request:
$body = file_get_contents('php://input');
$payload = json_decode($body,true);
$email = $payload['email'];
$password = $payload['password'];