<?php
$postDate = array(
'title' => '天气好',
'content' => '今天是星期三',
); // 要发送的数据
$postDate = http_build_query($postDate); // 使用给出的关联(或下标)数组生成一个 url-encoded 请求字符串。
$opts = array(
'http'=>array(
'method'=>"POST",// post请求
'header'=>"Host:localhost\r\n" .
"Content-type:application/x-www-form-urlencoded\r\n" .
"Content-length:".strlen($postDate)."\r\n", // 首部 \r\n 回车换行
'content' => $postDate,// 内容
)
);
$context = stream_context_create($opts);//创建并返回一个资源流上下文,该资源流中包含了提前设定的所有参数的值。
file_get_contents("http://localhost/index2.php",false,$context);// 发送(关键是第三个参数)
?>
$postDate = array(
'title' => '天气好',
'content' => '今天是星期三',
); // 要发送的数据
$postDate = http_build_query($postDate); // 使用给出的关联(或下标)数组生成一个 url-encoded 请求字符串。
$opts = array(
'http'=>array(
'method'=>"POST",// post请求
'header'=>"Host:localhost\r\n" .
"Content-type:application/x-www-form-urlencoded\r\n" .
"Content-length:".strlen($postDate)."\r\n", // 首部 \r\n 回车换行
'content' => $postDate,// 内容
)
);
$context = stream_context_create($opts);//创建并返回一个资源流上下文,该资源流中包含了提前设定的所有参数的值。
file_get_contents("http://localhost/index2.php",false,$context);// 发送(关键是第三个参数)
?>