I have a simple PHP web service sitting on our server.
I am able to connect to this service without any errors using the following code (I've removed our domain):
$service_url = '*** ADDRESS REDACTED! *** /getroomsforcategories.php';
$curl = curl_init();
$curl_post_data = array(
"categoryids" => 1
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_URL,$service_url."?categoryids=1");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . "/cacert.pem");
$curl_response = curl_exec($curl);
if ($curl_response===false)
echo "<p>Error ".curl_errno($curl)." - ".curl_error($curl);
else
{
echo "<pre>The CURL information:
";
print_r(curl_getinfo($curl));
echo "The response using cURL was:
";
print_r($curl_response);
echo "</pre>";
curl_close($curl);
}
I get no error from this, it seems to connect just fine (returns HTTP code 200).
The curl info displays as follows:
Array
(
[url] => *** REDACTED *** /getroomsforcategories.php?categoryids=1
[content_type] => text/html
[http_code] => 200
[header_size] => 348
[request_size] => 120
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.125
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0.109
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.125
[redirect_time] => 0
[certinfo] => Array
(
)
[redirect_url] =>
)
However, the curl response is completely empty.
The web service itself works fine - it is called throughout our software via AJAX using jQuery and works perfectly.
Any ideas on something I'm missing??
As a note, HTTP status codes have no correlation with the content length of the body returned. You may very well have a HTTP 200... but with a content length of 0 (which seems to be the case here? "download_content_length" is 0).
Have you checked on the server side to see what the problem might be here? (Oh, and since I assume this is over SSL, you might want to set 'CURLOPT_SSL_VERIFYPEER' to false, just to see if this is a problem with curl being unable to verify the certificate)