php file_get_contents curl发送cookie,使用代理

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:58   952   0

        $auth = base64_encode('LOGIN:PASSWORD');//LOGIN:PASSWORD 这里是你的账户名及密码  
        $aContext = array(  
            'http' => array(  
                'proxy' => 'tcp://192.168.0.2:3128',//这里设置你要使用的代理ip及端口号  
                'request_fulluri' => true,  
                'header' => "Proxy-Authorization: Basic $auth",  
            ),  
        );  
        $cxContext = stream_context_create($aContext);  
        $sFile = file_get_contents(http://www.phpfensi.com, False, $cxContext);  
        echo $sFile; 


<?php
function curl($url)
{
    $str_url = $url;
    $ch_curl = curl_init ();
    curl_setopt ( $ch_curl, CURLOPT_TIMEOUT, 3 );
    curl_setopt ( $ch_curl, CURLOPT_HEADER, false );
    curl_setopt ( $ch_curl, CURLOPT_HTTPGET, 1 );
    curl_setopt ( $ch_curl, CURLOPT_RETURNTRANSFER, true );
    curl_setopt ( $ch_curl, CURLOPT_URL, $str_url );
    
    //HTTP的代理
    $proxy="192.168.168.251:80";
    curl_setopt($ch_curl, CURLOPT_HTTPPROXYTUNNEL,true);
    curl_setopt($ch_curl, CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
    curl_setopt($ch_curl, CURLOPT_PROXY, $proxy);
    //curl_setopt($ch_curl, CURLOPT_PROXYUSERPWD, '');
     
    /*
    //Sock 4 的代理
    curl_setopt($ch_curl, CURLOPT_PROXYTYPE,4);
    //Sock 5 的代理
    curl_setopt($ch_curl, CURLOPT_PROXYTYPE,5);
     */
    $str_return = curl_exec ( $ch_curl );
    if ($str_return === false)
    {
        return false;
    }
    curl_close ( $ch_curl );
    return $str_return;
}
$url = "http://p1.img.cctvpic.com/xiyou/userimage/2012/10/18/163312135054919266639.jpg";
$contents = curl($url);
var_dump($contents);
file_put_contents("/tmp/1p.jpg",$contents);
?>


转载于:https://www.cnblogs.com/lein317/p/5067549.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP