1.POST请求
$domain='blog.163.com';
$file='http://blog.163.com/interface.php';
$condition='limit=12&count='.$usernum;
$data17=getblogdata($domain,$condition,$file);
function getblogdata($ip,$condition,$url){ $req=$condition; $header .= "POST $url HTTP/1.0/r/n"; $header .= "Content-Type: application/x-www-form-urlencoded/r/n"; $header .= "Content-Length: " . strlen($req) . "/r/n/r/n"; $fp = fsockopen ($ip,80, $errno, $errstr,30); if(!$fp){ _log('--ERROR--'.$ip.' can not open'); }else{ while (!feof($fp)) { fputs ($fp, $header . $req); $res = fgets ($fp, 204800); } } fclose ($fp); return $res; }
2.GET请求
$url = 'http://www.xxx.com/interface.php?cpid='.$cpid.'&qid='.$qid;
$_result = SendGET($url);
print_r($_result);
function SendGET($_url){ $url = parse_url($_url); $contents = ''; $url_port = $url['port']==''?80:$url['port']; $fp = fsockopen($url['host'],$url_port); if($fp){ $_request = $url['path'].($url['query']==''?'':'?'.$url['query']).($url['fragment']==''?'':'#'.$url['fragment']); fputs($fp,'GET '.(($_request=='')?'/':$_request)." HTTP/1.0/r/n"); fputs($fp,"Host: ".$url['host']."/n"); fputs($fp,"Content-type: application/x-www-form-urlencoded/n"); fputs($fp,"Connection: close/n/n"); $line = fgets($fp,1024); if(!eregi("^HTTP/1/.. 200", $line)) return; else{ $results = ''; $contents = ''; $inheader = 1; while(!feof($fp)){ $line = fgets($fp,2048); if($inheader&&($line == "/n" || $line == "/r/n")){ $inheader = 0; }elseif(!$inheader){ $contents .= $line; } } fclose($fp); } } return $contents; }
