1

I'm trying to get response using the Google Safe Browsing Lookup API like this:

$url ="https://sb-ssl.google.com/safebrowsing/api/lookup?client=myappname&apikey=mykey&appver=1.0&pver=3.0&url=".urlencode($myurl);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
$body = curl_exec($ch);
$info = curl_getinfo($ch);

I know that my URL is correct since if I dump it and then paste it to the browser I get the expected result (for example 'malware'). So I am assuming it must be something with cURL. I'm working on localhost and extension=php_curl.dll is un-commented in my php.ini, Php version 5.4.4

The html_code is always 0

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
cksrc
  • 2,062
  • 3
  • 24
  • 39
  • What is var_dump($body); returning if you put it after the last line of your code? – Zvonko Biskup Sep 17 '12 at 13:41
  • @webbandit the $body is FALSE – cksrc Sep 17 '12 at 13:49
  • 1
    `curl_exec();` - If the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, `FALSE` on failure. Use `var_dump(curl_error($c))` right after `$body = curl_exec($c);` to inspect error. – s.webbandit Sep 17 '12 at 13:52
  • @webbandit thanks! The error report is "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" – cksrc Sep 17 '12 at 13:58

2 Answers2

1

Simply set CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to false.

Anything wrong with my cURL code (http status of 0)?

Also check http://code.google.com/p/twitter-api/issues/detail?id=1291 , it might help. It is different APIs, but with the same problem anyway.

Community
  • 1
  • 1
Cedric
  • 5,135
  • 11
  • 42
  • 61
  • I already had CURLOPT_SSL_VERIFYPEER set to false, setting also CURLOPT_SSL_VERIFYHOST to false didn't change anything :( – cksrc Sep 17 '12 at 13:54
1

The problem and its solution is very nicely described here:

http://richardwarrender.com/2007/05/the-secret-to-curl-in-php-on-windows/

Basically if you are not using a standalone version of cURL the chances are that the cURL functions do not include a certificate bundle which was needed in my case since I was trying to connect to secure host.

$ch = curl_init();
// Apply various settings
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CAINFO, "C:/xampp/ca-bundle.crt"); //path to the CA-bundle
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec ($ch);
curl_close($ch);
cksrc
  • 2,062
  • 3
  • 24
  • 39