【问题标题】:cURL to get response from Google Safe Browsing LookupcURL 从 Google 安全浏览查找中获取响应
【发布时间】:2012-09-09 17:44:12
【问题描述】:

我正在尝试使用 Google Safe Browsing Lookup API 获得响应,如下所示:

$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);

我知道我的 URL 是正确的,因为如果我转储它然后将其粘贴到浏览器,我会得到预期的结果(例如“恶意软件”)。 所以我假设它一定是带有 cURL 的东西。我正在使用 localhost 并且 extension=php_curl.dll 在我的 php.ini 中未注释,Php 版本 5.4.4

html_code 始终为 0

【问题讨论】:

  • 什么是var_dump($body);如果你把它放在代码的最后一行之后返回?
  • @webbandit $body 是假的
  • curl_exec(); - 如果设置了 CURLOPT_RETURNTRANSFER 选项,它将在成功时返回结果,FALSE 在失败时返回。在$body = curl_exec($c); 之后使用var_dump(curl_error($c)) 检查错误。
  • @webbandit 谢谢!错误报告是“SSL证书问题,验证CA证书是否正常。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败”

标签: php curl


【解决方案1】:

只需将 CURLOPT_SSL_VERIFYPEER 和 CURLOPT_SSL_VERIFYHOST 设置为 false。

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

同时检查 http://code.google.com/p/twitter-api/issues/detail?id=1291 ,它可能会有所帮助。它是不同的 API,但无论如何都有相同的问题。

【讨论】:

  • 我已经将 CURLOPT_SSL_VERIFYPEER 设置为 false,也将 CURLOPT_SSL_VERIFYHOST 设置为 false 并没有改变任何东西:(
【解决方案2】:

这里很好地描述了这个问题及其解决方案:

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

基本上,如果您不使用独立版本的 cURL,则 cURL 函数可能不包含我的情况所需的证书包,因为我试图连接到 secure 主机。

$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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    相关资源
    最近更新 更多