2013-11-27 47 views
1

我想在本地服务器上执行此代码。它给出了响应,但是当我尝试在实时舞台服务器上运行相同的代码时,它会返回404错误。PHP cURL无法在活动服务器上使用代理服务器

$url = "http://www.google.com/search?q=saree&num=100&start=0&pws=0"; 
$name = $name; 

$encoded = $url.$name; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_PROXY, '111.119.226.129'); 
curl_setopt($ch, CURLOPT_PROXYPORT,'80'); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
$exec = curl_exec($ch); 
curl_close ($ch); 

我使用此代码的随机有效代理,并且我确定该代理是有效的。

任何人都可以帮助我吗?

+0

我有同样的问题弄来 –

+0

禁用服务器防火墙就能解决问题 –

回答

2

这些添加到您的代码,并尝试

$url = "http://www.google.com/search?q=saree&num=100&start=0&pws=0"; 
$name = $name; 

$encoded = $url.$name; 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1"); 
    curl_setopt($ch, CURLOPT_HEADER, $url); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //set headers 
    curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // set true for https urls 
+0

仍然没有工作的任何解决方案。 –

+1

您应该尝试使用此代码来查找错误。使用error_reporting(E_ALL); ini_set('display_errors',1); – 2013-11-27 10:40:51