php 调用远程url

// ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
// ; http://php.net/allow-url-fopen
// allow_url_fopen = On
//前三个都需要开启 allow_url_fopen
//1、file_get_contents()///////////////////////
$file = file_get_contents("http://www.baidu.com");
//2、fopen()///////////////////
$file2 = fopen("http://www.baidu.com","r");
while(!feof($file2)){
        $file2_content .= fgets($file2);    
}
//3、file()////////////////////////////////////////////
$file3 = file("http://www.baidu.com");
//4、fsockopen()//////////////////////////////////////////
//print_r(stream_get_transports());//获取已注册的套接字传输协议列表
$fp = fsockopen("www.cnblogs.com", 80, $errno, $errstr, 30); 
if (!$fp) { 
    echo "$errstr ($errno) "; 
} else { 
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: www.cnblogs.com.com\r\n";
   $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out); 
    while (!feof($fp)) { 
     echo fgets($fp, 128); 
    } 
    fclose($fp); 
}

 

posted @ 2017-04-14 14:42  S3c0ldW4ng  阅读(211)  评论(0编辑  收藏  举报