其實直接使用fopen就可以啦!!
不過有看到別人寫了別的方法
避免allow_url_fopen = off 而不能用的方法
function SendGET($_url){
$url = parse_url($_url);
$contents = '';
$fp = fsockopen($url['host'],$url['port']);
if($fp){
$_request = $url['path'].($url['query']==''?'':'?'.$url['query']).($url['fragment']==''?'':'#'.$url['fragment']);
fputs($fp,'GET '.$_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;
}
$url = 'http://someone.com:80/index.php?mode=go&id=hsin#top';
$_result = SendGET($url);
print_r($_result);
沒有留言:
張貼留言