1

我有这个简单的代码

<?php
$json = array("status" => $_POST['name']);
header('Content-type: application/json');
echo json_encode($json);
?>

当我发送 POST 数据时Advanced REST cliend,总是有一个空的 $_POST 表。 在此处输入图像描述

4

1 回答 1

2

您使用了错误的运输方式。如果您想读取 $_POST 数组中的 POST 数据,您必须将其作为多部分或 www 形式的 urlencoded 发送。

要阅读请求正文,您必须使用以下代码:

$postdata = file_get_contents("php://input");

然后您可以解析 JSON 并将其转换为对象。

如果要使用$_POST数组从请求中读取数据,则需要将 Content-Type 标头设置为application/x-www-form-urlencoded并将数据发送为:

param-name=param+value

(请注意,它是 url 编码的)。

于 2016-06-14T09:48:06.073 回答