我正在尝试寻找一种替代方法来读取 php://input。我用它从 CURL PUT 中获取 XML 数据。
我通常这样做:
$xml = file_get_contents('php://input');
但是,我在 Windows 上使用 file_get_contents()
时遇到了一些问题。
是否有替代方案,也许使用 fopen()
或 fread()
?
最佳答案
是的,你可以这样做:
$f = fopen('php://input', 'r');
if (!$f) die("Couldn't open input stream\n");
$data = '';
while ($buffer = fread($f, 8192)) $data .= $buffer;
fclose($f);
但是,您必须问自己的问题是,为什么 file_get_contents
不能在 Windows 上运行?因为如果它不起作用,我怀疑 fopen
是否适用于相同的流...
关于php - 在 PHP 中读取原始 I/O 流的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4876056/