php - file_get_contents ('php://input' ) 通过 PUT 请求返回空字符串

标签 php fastcgi iis-8.5

在通过 FastCGI 将我们的一个网站从带有 Apache 的 Linux 移动到带有运行 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>

结果是:

POST:

Working

PUT:

Not working

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

最佳答案

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

关于php - file_get_contents ('php://input' ) 通过 PUT 请求返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28611106/

相关文章:

php - 如何在 laravel 控制台命令中显示异常跟踪?

php - 自定义 php.ini - 似乎没有任何作用 - 你有什么建议? FastCGI-php 模式 -allow_url_fopen 关闭

testing - fcgi 脚本是如何测试的?

c# - 当文件名由 ASP.NET Web API Controller 确定时如何使用 IIS 压缩和缓存文件

本地发布灯开关

php - MySQL数据库性能

PHP - 回显颜色变量

php - 使用 PHP 清除表值

lighttpd 上的 Django : redirecting to . fcgi (404)

powershell - Powershell,使用msdeploy启动或停止iis站点