get
//建立连接
$fp=fsockopen("localhost",80,$errno,$errstr,30);
if(!$fp){
echo "$errstr $errno"die;
}
//请求行
$out="GET /myproject/html/server.php?username=admin&page=12 HTTP/1.1\r\n";
//请求头
$out.="Host: localhost\r\n";
$out.="Connection: Close\r\n\r\n";
//发送
fwrite($fp, $out);
//提取结果
while(!feof($fp)){
echo fgets($fp);
}
?>
post
//创建连接
$fp=fsockopen("localhost",80,$errno,$errstr,10);
//判断
if(!$fp){
echo "$errstr $errno";die;
}
$http="";
//请求行
$http.="POST /myproject/html/server.php HTTP/1.1\r\n";
//请求头
$http.="Host: localhsot\r\n";
$http.="Connection: Close\r\n";
$http.="Cookie: username=admin;uid=123456\r\n";
$http.="User-agent: firefox-chrome-safari-ios-android\r\n";
$http.="Content-type: application/x-www-form-urlencoded\r\n";
$http.="content-length: 37\r\n\r\n"; //请求头和请求体之间要有两个\r\n
//请求体
$http.="email=xiaohigh@&username=admin\r\n";
//发送
fwrite($fp, $http);
//提取结果
while(!feof($fp)){
echo fgets($fp);
}```