程式碼如下:
//post.php
function Post($host,$port)
{
//$host="127.0.0.1";
//建立連線 = host,$port);
if (!$conn)
{
die("Con 錯誤");
}
//循環發送5次資料
//
for($i = 0;$i{
$data="user_name=admin".$i;
WriteData($conn,$host,$data);
echo $i。 "
";
}
fclose($conn);
}
function WriteData($conn,$host,$data)
{
$header = "POST /test,$data)
{
$header = "POST /test,$data)
{
$header = "POST /test.php HTTP/1.1.1]; $header.= "主機: {$host}rn";
$header.= "內容類型:application/x-www-form-urlencodedrn";
$header.= "內容長度:".strlen($data) ."rn";
//Keep-Alive 是關鍵
$header.= "Connection: Keep-Alivenrn";
$header.= "{$data}rnrn";
fwrite($conn,$header);
//取得結果
//$result = '';
//while(!feof($conn))
//{