我有这个简单的代码
<?php
$json = array("status" => $_POST['name']);
header('Content-type: application/json');
echo json_encode($json);
?>
我有这个简单的代码
<?php
$json = array("status" => $_POST['name']);
header('Content-type: application/json');
echo json_encode($json);
?>
您使用了错误的运输方式。如果您想读取 $_POST 数组中的 POST 数据,您必须将其作为多部分或 www 形式的 urlencoded 发送。
要阅读请求正文,您必须使用以下代码:
$postdata = file_get_contents("php://input");
然后您可以解析 JSON 并将其转换为对象。
如果要使用$_POST
数组从请求中读取数据,则需要将 Content-Type 标头设置为application/x-www-form-urlencoded
并将数据发送为:
param-name=param+value
(请注意,它是 url 编码的)。