普通代理:

$aContext = array(
'http' => array(
'proxy' => 'tcp://代理IP:代理端口',
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);
$content = file_get_contents("http://目标网址", False, $cxContext);

有帐号密码的代理:

$auth = base64_encode('登录帐号:密码');
$aContext = array(
'http' => array(
'proxy' => 'tcp://代理IP:代理端口',
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth",
),
);
$cxContext = stream_context_create($aContext);
$content = file_get_contents("http://目标网址", False, $cxContext);

整理自:http://www.phpfensi.com/php/20140712/3747.html

Related Posts: PHP-file_get_contents 设置代理方法 :