fopen构造post
file_get_contents()构造post
模拟数据提交:get或post方式。
1、file_get_cntents():
http_build_query(array());
stream_context_create();
2、fopen();
post模拟提交所需的格式
fopen(filename,mode,include_path,context)
fopen() 将 filename 指定的名字资源绑定到一个流上。如果 filename 是 "scheme://..." 的格式,则被当成一个 URL,PHP 将搜索协议处理器(也被称为封装协议)来处理此模式。如果该协议尚未注册封装协议,PHP 将发出一条消息来帮助检查脚本中潜在的问题并将 filename 当成一个普通的文件名继续执行下去。
<?php
$postData = array(
'action' => 'req',
'type' => 'post'
);
$postData = http_build_query($postData);
$ops = array(
'http' => array(
'method' => 'POST',
'header' => "Host:localhost\r\nContent-type:application/x-www-form-urlencoded\r\nContent-length:" . strlen($postData)."\r\n",
'timeout' => 60,
'content' => $postData
),
);
$context = stream_context_create($ops);
echo file_get_contents('http://127.0.0.1/reg.php', false, $context);
exit;
//注意file_get_contents的链接里必须加http://
?>