请求页面:
$data = array(
'name' => 'jack',
'website' => 'www.baidu.com'
);
function post($url,$data = [],$json = false)
{
$str = 'application/x-www-form-urlencoded';
$final_data = http_build_query($data);
if($json){
$str = 'application/json';
$final_data = json_encode($data);
}
$options[ 'http' ] = array(
'timeout' => 5,
'method' => 'POST',
'header' => "Content-Type: $str;charset=utf-8",
'content' => $final_data,
);
$context = stream_context_create($options);
return file_get_contents($url, false, $context);
}
$r= post('http://localhost/1.php',$data,true);
echo $r;
接收页面:
$json=file_get_contents('php://input');
echo $json;