donglun4521 2015-02-19 16:08
浏览 93
已采纳

file_get_contents('php:// input')返回带有PUT请求的空字符串

After moving one of our websites from Linux with Apache to Windows with IIS (8.5) running PHP 5.6 via FastCGI, we've run into the problem that file_get_contents('php://input') returns an empty string for PUT requests.

I've created the following test:

<?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>

Which results in:

POST:

Working

PUT:

Not working

What could be causing this?

  • 写回答

1条回答 默认 最新

  • douyan9417 2015-02-22 20:18
    关注

    As it turns out the problem is caused by the Helicon Ape module (a module for supporting Apache .htaccess and .htpasswd configuration files). Removing this module fixes the problem, but I still don't know why it would interfere with PUT requests. I guess I'll have to post a topic on their forum with this issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码