阅读更多
一.GET方式:
$host_ip = '127.0.0.1';
$host_domain = 'www.example.com';
$getway = '/index.php?uid=xxx&pw=xxx';
GET_HTTP($host_ip,$host_domain,$getway);
function GET_HTTP($host_ip,$host_domain,$getway)
{
$fp = fsockopen ($host_ip, 80, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)
\n";
}
else
{
$out = "GET ".$getway." HTTP/1.1\r\n";
$out .= "Host: ".$host_domain."\r\n";
$out .= "Accept: */*\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
$content.=fgets($fp, 128);
}
fclose($fp);
$pager=explode("\n",$content);
$get_content = $pager[4];
}
return $get_content;
}
?>
二.POST方式:
$host = 'http://www.example.com/index.php';
$query = 'uid=xxx&pw=xxx';
POST_HTTP($host,$query);
function POST_HTTP($host,$query,$others='')
{
$path=explode('/',$host);
$host=$path[0];
unset($path[0]);
$path='/'.(implode('/',$path));
$post="POST $path HTTP/1.1\r\nHost: $host\r\n";
$post.="Content-type: application/x-www-form-";
$post.="urlencoded\r\n${others}";
$post.="User-Agent: Mozilla 4.0\r\nContent-length: ";
$post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$r='';!$a;)
{
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
return $r;
}
?>
文章转载于 www.ikown.com.