PHP 5.6.2
我有输入脚本curlTest.php
<?php
print_r(array($_GET, $_POST, file_get_contents('php://input')));
?>写我运行的内容:
<?php
$url = 'http://localhost/curlTest.php';
$data = 'test-data';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>我有这样的产出:
Array
(
[0] => Array
(
)
[1] => Array
(
[test-data] =>
)
[2] => test-data
)为什么php在_POST中解析我的输入数据?但是在PHP 5.2.6上的另一台机器上,我有另一个输出:
Array
(
[0] => Array
(
)
[1] => Array
(
)
[2] => test-data
)有什么想法吗?
发布于 2014-11-17 16:42:18
你在做:
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);设置POSTFIELDS会自动告诉curl你在写一篇文章。
post/get数据是关键:值对。您已经($data)提供了PHP作为没有值的键进行解析的内容,因此基本上得到了$_POST['test-data'] = null。POST数据通过STDIN传递给脚本,这就是为什么php://input向您展示测试数据的原因。
https://stackoverflow.com/questions/26977369
复制相似问题