POST 无法读取通过 url 发送的变量

POST cannot read variables sent via url

我使用 PHP 创建了一个 REST API 以使用 JsonObjectRequest 从我的 Android 应用程序接收数据。我正在通过在 Postman 中使用以下 url 调用它来测试 API,但是我的 PHP 应用程序告诉我它没有收到 params

URL: http://192.168.2.15/login_api/login.php?email=test@test.com&password=test

这是我的 login.php:

<?php

require_once 'include/DB_Functions.php';
$db = new DB_Functions();

$response = array("error" => FALSE);

if (isset($_POST['email']) && isset($_POST['password'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];

    $user = $db->getUserByEmail($email, $password);

    if ($user != FALSE) {
        $response["error"] = FALSE;
        $response["uid"] = $user["unique_id"];
        $response["user"]["name"] = $user["name"];
        $response["user"]["email"] = $user["email"];
        $response["user"]["date_created"] = $user["date_created"];
        echo json_encode($response);
    } else {
        $response["error"] = TRUE;
        $response["error_msg"] = "User does not exist!";
        echo json_encode($response);
    }
} else {
    $response["error"] = TRUE;
    $response["error_msg"] = "Required parameters are missing!";
    echo json_encode($response);
}   
?>

我总是得到 Required parameters are missing!。有人可以帮我解决这个问题吗?

URL 中的所有变量,如您的 http://192.168.2.15/login_api/login.php?email=test@test.com&password=test 都是 GET 参数

Yoy 正在通过 GET 方法发送数据

这不是 POST。这是 GET 。我根据 GET 方法更改了您的代码。

<?php

require_once 'include/DB_Functions.php';
$db = new DB_Functions();

$response = array("error" => FALSE);

if (isset($_GET['email']) && isset($_GET['password'])) {
    $email = $_GET['email'];
    $password = $_GET['password'];

    $user = $db->getUserByEmail($email, $password);

    if ($user != FALSE) {
        $response["error"] = FALSE;
        $response["uid"] = $user["unique_id"];
        $response["user"]["name"] = $user["name"];
        $response["user"]["email"] = $user["email"];
        $response["user"]["date_created"] = $user["date_created"];
        echo json_encode($response);
    } else {
        $response["error"] = TRUE;
        $response["error_msg"] = "User does not exist!";
        echo json_encode($response);
    }
} else {
    $response["error"] = TRUE;
    $response["error_msg"] = "Required parameters are missing!";
    echo json_encode($response);
}   
?>