php curl 代理ip訪問url

來源:互聯網
上載者:User

標籤:else   資訊   方式   host   return   請求   res   nec   useragent   

網上很多代理ip來訪問url,具體幹什麼我也不知道,寫代碼:

$header //要求標頭

$cookie //儲存cookie

$arrip //ip地址的地址及連接埠

$params //

public function dorequest($arrip = array(),$url,$header,$timeout = 20000,$method=‘,$cookie‘){

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         

curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理認證模式  

curl_setopt($ch, CURLOPT_PROXY, "$arrip[0]"); //Proxy 伺服器地址   

curl_setopt($ch, CURLOPT_PROXYPORT,$arrip[1]); //Proxy 伺服器連接埠

 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https請求 不驗證認證和hosts   

 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);     

curl_setopt($ch, CURLOPT_URL, $url);//設定連結    

 //curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0");

  if(!defined(‘CURLOPT_TIMEOUT_MS‘)){   

 $res = curl_setopt($ch, CURLOPT_TIMEOUT,30); //設定1秒逾時  

 }

else {

   curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout);

  }        

 if ($cookie) {

   curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie);//儲存cookies    

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);   }

  if(!defined(‘CURLOPT_CONNECTTIMEOUT_MS‘))

{    

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);  

 } else {   

 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $timeout);   }  

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//設定是否返回資訊   

$method = strtoupper($method);  

 if($method == ‘POST‘){   

 curl_setopt($ch, CURLOPT_POST, 1);//設定為POST方式    

curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));  

 }

  if($header)

{    

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);  

 }   //設定跳轉location 最多3次  

 curl_setopt($ch, CURLOPT_MAXREDIRS, 3);     

 $response = curl_exec($ch);//接收返回資訊

}

php curl 代理ip訪問url

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.