用户名(username):温柔一刀
密码(pwd):&123=321&321=123&个人简介(intro):Hello world!
cur_query:you&me
last_tm:...(上次请求的unix时间戳,定为当前请求时间前10分钟) cur_tm:...(当前请求的unix时间戳)
设置超时为10秒,发出请求后,将http server的响应内容输出(腾讯)
<?php
if($fp = fsockopen('localhost','80')){
//连接成功
$request_data="POST/2.php HTTP/1.1"."\r\n";//请求行
$request_data.="Host:localhost"."\r\n";//host头信息
$request_data.="User-Agent:Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"."\r\n";//host头信息
$request_content="username=".urlencode('温柔一刀')
."&pwd=".urlencode('&123=321&321=123&')
."&intro=".urlencode("Hello world!");
$request_data.="Content-Type:application/x-www-form-urlencoded"."\r\n";
$request_data.="Content-Length:".strlen($request_content)."\r\n";
$cur_query=urlencode("you&me");
$last_tm=time()-10*60;
$cur_tm=time();
$request_data.="Cookie:cur_query=$cur_query;last_tm=$last_tm;cur_tm=$cur_tm"."\r\n";
$request_data.="\r\n";//请求头信息结束时的空行
//请求主体数据部分
$request_data.=$request_content;
//利用建立好的通道,将数据发送过去
fwrite($fp,$request_data);//写入数据(发送数据)
//读取数据
while(!feof($fp)){//判断是否没有到文件末尾
$resp_data=fgets($fp);
echo$resp_data.'<br>';
}
}
?>