【发布时间】:2015-09-18 20:19:31
【问题描述】:
如何从服务器端读取用户名和密码。如果我使用 POST 方法而不是 GET,那么我可以通过
轻松阅读$REQUEST = file_get_contents('php://input');
$REQUEST = json_decode($REQUEST, true);
echo json_encode($REQUEST);
这段代码。我可以得到回应 {“用户名”:“muradcse1”,“密码”:“1122”}
但是如果方法是get,那么读取json格式数据的方法是什么?我也需要这种格式的 get 方法。
请帮忙。
【问题讨论】:
-
json_decode() 将允许您将所有 json 数据呈现到 php 数组中。
-
谢谢@Idealcastle 我应该在 json_decode() 函数中传递什么?假设 $REQUEST = file_get_contents('php://input'); $REQUEST = json_decode($REQUEST, true); "file_get_contents('php://input')" 不适用于 get 方法,但适用于 post。