cURL "Couldn't connect to host"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mince
Forum Commoner
Posts: 25
Joined: Mon Aug 03, 2009 9:36 am

cURL "Couldn't connect to host"

Post by Mince »

Hi All

I'm struggling to get cURL working via a proxy server. Below is my code:

Code: Select all

<?php
if (extension_loaded('curl')) 
{
$url = "myip:8080/httppost_test/recieve.php?tester=testcurl";
//$url = "http://www.google.com";
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_HEADER, false); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15); // timeout after 5 seconds
curl_setopt ($ch, CURLOPT_TIMEOUT, 30); // timeout after 30 seconds 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST|CURLAUTH_GSSNEGOTIATE|CURLAUTH_NTLM|CURLAUTH_ANY|CURLAUTH_ANYSAFE);
curl_setopt($ch, CURLOPT_PROXYPORT, 80);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, '[user]:[password]');

$result = curl_exec ($ch); 
 
var_dump(curl_error($ch)); // for debugging
curl_close ($ch);
var_dump($result);	
}
?>
The result is always string(24)"couldn't connect to host" for the curl_error and bool(false) for the $ch
Even if i try http://google.com i get the same error

Any suggestions?
Thanks
Marinus
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: cURL "Couldn't connect to host"

Post by requinix »

And you're specifying the location of the proxy server... where?
Mince
Forum Commoner
Posts: 25
Joined: Mon Aug 03, 2009 9:36 am

Re: cURL "Couldn't connect to host"

Post by Mince »

Ah yes.. :oops:

Added: curl_setopt($ch, CURLOPT_PROXY, "myProxy");
And it still didn't work.

Then tried removing the square brackets around the username and password, and now it works perfectly!

Thanks so much for the help, I have been struggling with this stuff for ages now!

Regards
Marinus
Post Reply