Phpcurl is accessed by proxy. the server can. it cannot be accessed locally.

Source: Internet
Author: User
Phpcurl is accessed by proxy. the server can. if it is not tested locally, use the & nbsp; curl proxy for access. the test is feasible on the server, but the result is blank on the local server. ask what the situation is, the proxy ip address is found online. function & nbsp; curl_string & nbsp; ($ url, $ user_agent, $ proxy) {& nbsp; & nbsp; & nb php curl can be accessed by proxy on the server, but cannot be accessed locally
The test uses a curl proxy for access. the test is feasible on the server, but the result is blank on the local device. for details, refer to the situation where the proxy ip is found online and available.


function curl_string ($url,$user_agent,$proxy){

$ch = curl_init();
curl_setopt ($ch, CURLOPT_PROXY, $proxy);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec ($ch);
curl_close($ch);
return $result;

}

$url = "http://www.baidu.com";
$user_agent = "Mozilla/4.0";
$proxy = "http://111.13.109.53:80";
$string = curl_string($url,$user_agent,$proxy);
echo $string;




------ Solution ----------------------
111.13.109.53 Beijing Mobile
Ping failure
Access http: // 111.13.109.53: 80 does not exist

Apparently a protected ip address
------ Solution ----------------------
The proxy ip cannot be pinged. how can you access Baidu based on the proxy?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.