PHP 初学者 使用cURL并用代理访问http

来源:互联网 发布:数据存储软件 编辑:程序博客网 时间:2024/05/30 05:25

 有些公司需要通过代理来上网。所以必须使用代理,并输入用户名和密码才能使用http.

 

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.sina.com.cn");
curl_setopt($ch, CURLOPT_HEADER, true);

 

curl_setopt ($ch, CURLOPT_PROXY, "http://192.168.0.1:3128");/代理网址和端口
curl_setopt ($ch, CURLOPT_PROXYUSERPWD, 'myName:pwd'');

 

访问https:还要加这个.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

 

// grab URL and pass it to the browser
$result = curl_exec($ch);
if ($result= true) {
 echo ($ch);
}

// close cURL resource, and free up system resources
curl_close($ch);
?>