0

我有 PHP 应用程序尝试使用 'file_get_contents' 函数在 'php://input' 中获取 post JSON。只返回空字符串。下面是完整的代码行。

$_PUT = json_decode(file_get_contents("php://input"), true);

或者我需要更改任何 apache/php 设置?

4

1 回答 1

1

我正在使用这个标题'Content-Type': 'application/x-www-form-urlencoded'

如果您的数据是 application/x-www-form-urlencoded,那么您应该通过$_POST而不是接触原始 HTTP 请求正文来访问它。只有在使用非典型内容类型(例如application/json)时才这样做。

如果您的数据不是该格式,那么您应该使用正确的 Content-Type 标头。

于 2012-10-24T08:57:04.570 回答