【问题标题】:Remote post data of json not populating $_POSTjson 的远程发布数据未填充 $_POST
【发布时间】:2013-06-08 22:12:33
【问题描述】:

我有一个标准版本的 Apache,在 Ubuntu 12.04 和 PHP 5.3.10 上运行。

我希望在其上运行 REST 服务器,但遇到了问题。目前有一个 index.php 正在执行print_r($_POST);

通过使用此工具https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo/ 我将数据发布到页面。如果我将要发送的数据设置为 x-www-form-urlencoded,则会填充 $_POST 变量。

但是,如果我将要发送的数据设置为 application/json,则不会填充 $_POST 变量,但原始数据在 HTTP_RAW_POST_DATA 中可用。

我以这种方式进行测试的原因是这与我在运行 REST 服务器 (https://github.com/philsturgeon/codeigniter-restserver) 时看到的行为相同。所以我认为这一定是Apache的问题。

还有其他人遇到过这个问题吗?我在运行 REST 服务器方面没有太多经验,所以很可能是我做错了。

【问题讨论】:

  • 应该是这样的。
  • 我不明白?您将如何访问发布的数据?
  • but the raw data is available in HTTP_RAW_POST_DATA ...另见php.net/manual/en/…php.net/manual/en/…
  • 我之前没有实现过 REST 服务器,所以我有点挣扎。如果没有填充 $_POST 变量,那么我尝试实现的 REST 服务器将无法工作,但它对其他所有人都有效吗?
  • 如果您的问题是how to get the posted data?,那么很容易回答,但事实并非如此。

标签: apache2 php post


【解决方案1】:

应该是这样的。但是,如果您想要发布的数据,您可以

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

【讨论】:

    猜你喜欢
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多