http头部的格式和参数说明

时间:2025-02-17 12:53:08
{

$fp=fsockopen("",80,$errno,$errstr,30);


if(!$fp){


echo"$errstr($errno)

/n";


}else{


$out="POST/ HTTP/1.1/r/n";


$out.="Host:/r/n";


$out.="User-Agent:Mozilla/5.0(X11;U;Linux i686;en-GB;rv:1.9.2.15)Gecko/20110303 Ubuntu/10.04(lucid)Firefox/3.6.15/r/n";


$out.="Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8/r/n";


$out.="Accept-Language:en-gb,en;q=0.5/r/n";


$out.="Accept-Encoding:gzip,deflate/r/n";


$out.="Content-Type:application/x-www-form-urlencoded/r/n";


$out.="Content-Length:80/r/n";


$out.="Connection:Close/r/n/r/n";


$out.="email=youname%&password=youpasswd&act=login&redirectURL=&loginsubmit=/r/n/r/n";


fwrite($fp,$out);


while(!feof($fp)){


echo fgets($fp,128);


}


fclose($fp);


}


}


else


{


print_r($_REQUEST);


}


?>;


用php发送http请求的主要分两部(1)构造一个http头部的串.(2)用fsockopen打开socket连接。(3)再用fwrite把构造好的数据传送到请求主机