curl -d "id=1&name&age=12" http://localhost/post.php
我输出名称时遇到问题,因为它是空的
Array
(
[id] => 1
[age] => 12
)
如何获得结果
Array
(
[id] => 1
[age] => 12
[name] =>
)
答案 0 :(得分:1)
curl -d "id=1&name=&age=12" http://localhost/post.php
应该做的伎俩
答案 1 :(得分:1)
$var = 'id=1&name&age=12' ;
$text = explode('&',$var);
$text = array_flip($text);
if(!isset($text['name=']))
{
$var = str_replace('name','name=',$var);
}
echo $var ;
/* Should Return 'id=1&name=&age=12' always
答案 2 :(得分:0)
试试这个:
echo file_get_contents("php://input");
您可以使用
获得的正常参数parse_str(file_get_contents("php://input"), $_POST);
对于名称,您必须自己解析它。
$a = explode('$', file_get_contents("php://input"));
答案 3 :(得分:0)
如果name,id和age是固定参数,您可以使用默认数组并执行array_merge()
,如下所示:
<?php
$default = array('id' => '', 'name' => '', 'age' => '');
$variables = array_merge($default, $_POST);