PHP:file_get_contents的代理使用方法

正 文:
   PHP使用file_get_contents的代理方法获取远程网页的代码。

<?php
    $url = "http://www.piaoyi.org/";     
    $ctx = stream_context_create(array(     
       'http' => array('timeout' => 5,  
       'proxy' => 'tcp://60.175.203.243:8080',   
       'request_fulluri' => True,)     
    )     
    );     
    $result = file_get_contents($url, False, $ctx);     
    echo $result;  
?>
   

    另外一种 curl 的方式使用代理的方法:
function postPage($url)
{
$response = "";
$rd=rand(1,4);
$proxy='http://221.214.27.253:808';
if($rd==2) $proxy='http://222.77.14.56:8088';
if($rd==3) $proxy='http://202.98.123.126:8080';
if($rd==4) $proxy='http://60.14.97.38:8080';

if($url != "") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$response = curl_exec($ch);
if(curl_errno($ch)) $response = "";
curl_close($ch);
}
return $response;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值