【问题标题】:file_get_contents('php://input') returning empty string with a PUT requestfile_get_contents('php://input') 使用 PUT 请求返回空字符串
【发布时间】:2015-02-19 16:08:04
【问题描述】:

在将我们的一个网站从带有 Apache 的 Linux 移动到带有通过 FastCGI 运行 PHP 5.6 的 IIS (8.5) 的 Windows 之后,我们遇到了 file_get_contents('php://input') 为 PUT 请求返回空字符串的问题。

我创建了以下测试:

<?php
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && 
    strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    die(file_get_contents('php://input'));
}
?>
<!DOCTYPE html>
<html>
<head>
    <script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
    <h2>POST:</h2>
    <div id="post"></div>

    <h2>PUT:</h2>
    <div id="put"></div>
    <script>
        $.ajax({
            url: '?',
            data: 'Working',
            type: 'POST'
        }).then(function(response) {
            $('#post').html(response || 'Not working');
        });

        $.ajax({
            url: '?',
            data: 'Working',
            type: 'PUT'
        }).then(function(response) {
            $('#put').html(response || 'Not working');
        });
    </script>
</body>
</html>

结果:

发布:

工作

放置:

不工作

这可能是什么原因造成的?

【问题讨论】:

  • 可能与 IIS WebDAV 模块冲突。还要检查“处理程序映射”选项。

标签: php fastcgi iis-8.5


【解决方案1】:

事实证明,问题是由 Helicon Ape 模块(一个支持 Apache .htaccess 和 .htpasswd 配置文件的模块)引起的。 删除这个模块解决了这个问题,但我仍然不知道为什么它会干扰 PUT 请求。我想我必须在他们的论坛上发布一个关于这个问题的主题。

【讨论】:

  • PUT 用于安静的请求。
  • 到底是什么问题?我面临同样的问题!我还是想不通!
猜你喜欢
  • 2015-06-14
  • 2015-01-24
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 2014-02-11
  • 2011-05-09
相关资源
最近更新 更多