【发布时间】:2012-10-24 07:01:38
【问题描述】:
我有 PHP 应用程序尝试使用 'file_get_contents' 函数在 'php://input' 中获取 post JSON。只返回空字符串。下面是完整的代码行。
$_PUT = json_decode(file_get_contents("php://input"), true);
或者我需要更改任何 apache/php 设置?
【问题讨论】:
-
你是如何构建请求的?
-
来自文档:“php://input 不适用于 enctype="multipart/form-data"。”
-
请求使用 Angular $resource 和 JSON 格式的数据。所以@TobiasSpringer,我需要在发送帖子时修改标题?我正在使用这个标题
'Content-Type': 'application/x-www-form-urlencoded' -
如果你要 PUTing JSON,你应该使用
'Content-Type': 'application/json'。确保您跟踪请求,例如在 google chrome 网络选项卡中,以确保您实际发送请求正文
标签: php json rest file-get-contents