使用代理,使用curl,在本地主机上工作但不在服务器上工作

发布于 2024-11-29 06:02:00 字数 917 浏览 0 评论 0原文

我使用鱿鱼在我的一个 vps 上设置了一个代理,然后我制作了这个代理脚本,它在本地主机上的 wamp 上运行良好,但是当我将其上传到我的服务器时,它不起作用,我似乎无法弄清楚为什么。

$proxy = "xx.xx.xxx.xx:3128";
$proxy = explode(':', $proxy);
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/1.0 ([email protected] http://googlebot.com/)');
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8" ); 
curl_setopt($ch, CURLOPT_REFERER, "http://tamilwin.com/"); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec ($ch);

提前致谢。

更新

我在服务器上收到的错误是 cURL 错误号:7cURL 错误:无法连接到主机

I setup a proxy on one of my vps using squid, then i made this proxy script and it works fine on wamp, on localhost but when i upload it to my server its not working and I cannot seem to figure out why.

$proxy = "xx.xx.xxx.xx:3128";
$proxy = explode(':', $proxy);
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/1.0 ([email protected] http://googlebot.com/)');
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8" ); 
curl_setopt($ch, CURLOPT_REFERER, "http://tamilwin.com/"); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec ($ch);

thanks in advance.

Update

the error i get on my server is cURL error number:7cURL error:couldn't connect to host

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经暖 2024-12-06 06:02:00

代理主机可能无效。
尝试 telnet xx.xx.xxx.xx 3128(从本地 PC)
能连接成功吗?

The proxy host may be not valid.
try telnet xx.xx.xxx.xx 3128 (from your local PC)
Can you connect to it successfully?

非要怀念 2024-12-06 06:02:00

我遇到了类似的问题,在本地主机上工作得很好,但在我的服务器上却不行。我编写了一个检测脚本,可以让您知道它是否有效。

<?php

//$url = 'https://www.google.com';
// to check your proxy
$url = 'http://whatismyipaddress.com/';
$proxy = 'x.x.x.x:3128';

// create curl resource
$ch = curl_init();

// set options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true ); // read more about HTTPS http://stackoverflow.com/questions/31162706/how-to-scrape-a-ssl-or-https-url/31164409#31164409
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, file_exists('\cacert.pem'));
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy);


curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch); 

//echo $output;

$check = stripos($output,'</html>');
// if there was a match in the stripos (string postion) function echo that the
//proxy got the data and works
if($check > 0)
{
echo $proxy." Works!
";
// or else echo it doesn't work
}else{
echo $proxy." Is Dead!
";
}


?>

I'm having similar problems, works great on localhost but not on my server. I wrote a detection script which lets you know if it works or not.

<?php

//$url = 'https://www.google.com';
// to check your proxy
$url = 'http://whatismyipaddress.com/';
$proxy = 'x.x.x.x:3128';

// create curl resource
$ch = curl_init();

// set options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true ); // read more about HTTPS http://stackoverflow.com/questions/31162706/how-to-scrape-a-ssl-or-https-url/31164409#31164409
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, file_exists('\cacert.pem'));
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy);


curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch); 

//echo $output;

$check = stripos($output,'</html>');
// if there was a match in the stripos (string postion) function echo that the
//proxy got the data and works
if($check > 0)
{
echo $proxy." Works!
";
// or else echo it doesn't work
}else{
echo $proxy." Is Dead!
";
}


?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文