views:

22

answers:

1

Error is "Could not resolve host: (hostname); Host not found."

This randomly started happening again on my development computer. It works fine on the production server, so whatever. But I still need to test this here. Here's the code:

function useCurl($xml,$cert,$host){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$host);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

$result = curl_exec($ch);

if (curl_error($ch)) {
 print "cURL error: ". curl_error($ch) ."\n<br/>";
}

 curl_close($ch);
 return $result;
}

I know about the security vulnerabilities with these settings. But right now, I care more about getting this to work. HTTP addresses of course work fine, but those with HTTPS return no content and give an error about not being able to find the hostname. I've searched and didn't find anything useful this time.

A: 

Have you tried adding curl_setopt($ch, CURLOPT_PORT, 443); so that it connects to the server on the ssl enabled port?

Bocochoco
It does that implicitly though, and this same code works on another server. But no, that didn't help. If the problem isn't the code, then where is it?
Chris
What does `curl_error();` print?
Bocochoco
curl_error() = "Could not resolve host: (hostname); Host not found."
Chris