Page 1 of 1

cURL "Couldn't connect to host"

Posted: Mon Mar 19, 2012 5:20 am
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

Re: cURL "Couldn't connect to host"

Posted: Mon Mar 19, 2012 11:19 am
by requinix
And you're specifying the location of the proxy server... where?

Re: cURL "Couldn't connect to host"

Posted: Tue Mar 20, 2012 6:24 am
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