Proxy Authentication Required with cURL

前端 未结 4 1571
梦如初夏
梦如初夏 2020-12-14 03:33

I would like to use a cURL function, but I\'m behind a proxy, so I get an HTTP/1.1 407 Proxy Authentication Required error...

This is the php code I use

4条回答
  •  孤城傲影
    2020-12-14 04:06

    This is what I'm mostly using :

    function curlFile($url,$proxy_ip,$proxy_port,$loginpassw)
    {
        //$loginpassw = 'username:password';
        //$proxy_ip = '192.168.1.1';
        //$proxy_port = '12345';
        //$url = 'http://www.domain.com';
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
        curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
        curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
        $data = curl_exec($ch);
        curl_close($ch);
    
        return $data;
    }
    

提交回复
热议问题