我遇到了 file_get_contents("php://input") 的问题

I'm having troubles with file_get_contents("php://input")

我正在开发一个 Codeigniter 应用程序并使用 AngularJS 作为前端。

我在 PHP 7.4.6 中通过 file_get_contents("php://input") 获取 POST 数据,但 JSON 末尾带有数字 1。

示例:

{"credentials":{"email":"blablabla@hotmail.com","password":"12345678"}}1

我也尝试过使用 $this->input->post(),但它 returns 以下内容:

Array
(
)
1

以下是我用来从 POST 获取数据的函数:

public function getInputAngular()
{
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata, true);

    foreach ($request as $key => $value) {
        $request[$key] = str_replace("'", '', $value);
    }

    return $request;
}

当我向 CI 控制器中的以下函数发出请求时,我正在调用上一个函数:

public function handleLogin()
{
    $data = $this->funcoes_generica->getInputAngular(); 
}

问题出在我打印数据的方式上。

我的表现如何:

echo "<pre>";
echo print_r($postdata);
echo "</pre>";
exit;

正确的做法:

echo "<pre>";
print_r($postdata);
echo "</pre>";
exit;