在通过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>
结果是:
邮政:
在职的
放:
无法运作
是什么原因造成的?
事实证明,问题是由Helicon Ape模块(用于支持Apache .htaccess和.htpasswd配置文件的模块)引起的。删除此模块可解决此问题,但我仍然不知道为什么它会干扰PUT请求。我想我必须在这个问题上在他们的论坛上发布主题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句