How to use a PROXY in cURL ?

Discussion in 'PHP' started by stephane, Dec 2, 2009.

  1. #1
    Hi,

    I have a problem using a proxy in cURL. I am trying to use the code below and it does not work unless I put curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, 0); ( CURLOPT_HTTPPROXYTUNNEL set to 0 ). Can you help me ?

            
            $proxy = "217.174.242.152:3128";
            $ch = curl_init(); 
    	curl_setopt($ch, CURLOPT_URL, 'http://www.ip2location.com/'); 
    	curl_setopt($ch, CURLOPT_HEADER, true); 
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    	curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    	curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    	curl_setopt ($ch, CURLOPT_PROXY,"$proxy");
    	$data = curl_exec($ch); 
    	curl_close($ch);
    
    Code (markup):
    Thank you for helping.

    Stephane
     
    stephane, Dec 2, 2009 IP
  2. kajol

    kajol Well-Known Member

    Messages:
    523
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Check your proxy server may require authentication...
     
    kajol, Dec 3, 2009 IP
  3. ankit_frenz

    ankit_frenz Active Member

    Messages:
    1,111
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    63
    #3
    use this its should help
     
    ankit_frenz, Dec 3, 2009 IP