在将我们的一个网站从带有 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>
结果是:
邮政:
在职的
放:
不工作
这可能是什么原因造成的?