本文介绍了PHP cURL在活动服务器上不使用代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在本地服务器上执行此代码。它给出了响应,但是当我尝试在活舞台服务器上运行相同的代码时,它返回一个404错误。
$ 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);
我为此代码使用随机有效的代理,我确定代理有效。 p>
任何人都可以帮助我?
解决方案
尝试
$ 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); //为https urls设置为true
I want to execute this code on local server. It gives the response, but when I try to run the same code on live stage server, it returns a 404 error.
$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);
I use random valid proxies for this code, and I'm sure the proxy is valid.
Can anyone help me please?
解决方案
add these to your code and try
$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
这篇关于PHP cURL在活动服务器上不使用代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!