<?php
$data = array(
'name' => 'zhangsan',
'gender' => 'male',
'age' => 25
);
$query_string = http_build_query($data);
$option = array(
'http' => array(
'method' => 'POST',
'header' => array(
"Content-type:application/x-www-form-urlencoded",
"Contnet-length:".strlen($query_string)
),
'content'=> $query_string
)
);
$context = stream_context_create($option);
$url = 'http://localhost/test.php';
$content = file_get_contents($url,false,$context);
echo $content;
test.php文件:
<?php
print_r($_POST);
请求返回的结果:
Array ( [name] => zhangsan [gender] => male [age] => 25 )