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

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 12: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部