找到你要的答案

Q:php_curl not able to run https (Google+ API)

Q:php_curl无法运行的HTTPS(谷歌+ API)

I'm trying to pull the share count from Google+ using the code below:

function get_gplus_shares($url){
    $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
      $curl_results = curl_exec ($curl);
      curl_close ($curl);
      $json = json_decode($curl_results, true);
      return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}

It is working fine on my local test environment, but not working on my live environment. I've installed php_curl using sudo apt-get install curl and sudo apt-get install php5-curl, which is working fine. Also added the cacert.pem by sudo wget http://curl.haxx.se/ca/cacert.pem -O /usr/lib/ssl/certs/cacert.pem. But doesn't seem to work. I really don't know where to proceed with this.

Error Messages - from apache error log.

RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?) - but this error seems to fixed after adding cacert.pem.

PHP Notice: Undefined index: result - PHP error, as the result of the function is empty.

[ssl:error] [pid 20743] AH02032: Hostname **IP-ADDRESS** provided via SNI and hostname **mydomain.com** provided via HTTP are different - just saw this error, not sure if related.

我正试图从谷歌+使用下面的代码的份额计数:

function get_gplus_shares($url){
    $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
      $curl_results = curl_exec ($curl);
      curl_close ($curl);
      $json = json_decode($curl_results, true);
      return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}

它在我的本地测试环境中运行良好,但不在我的生活环境中工作。我已经安装使用sudo易于安装的php_curl卷曲和sudo apt-get安装PHP5的卷曲,这是工作的罚款。补充sudo wget http://curl.haxx.se/ca/cacert.pem O /usr/lib SSL /证书/ cacert.pem的cacert.pem。但似乎没有工作。我真的不知道从哪里着手。

错误消息从Apache错误日志。

RSA服务器证书CA证书(CA = =真basicconstraints!?)-但这个错误似乎加入cacert.pem固定。

注意:未定义的指标:PHP结果错误,作为函数的结果是空的。

[错误] [ SSL:PID 20743 ] ah02032:主机名** ip-address **通过SNI和主机名** MyDomain .com **通过HTTP是不同的——刚看到这个错误,不知道是否相关。

answer1: 回答1:

Can you please check by adding below two options

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
curl_setopt ($ch, CURLOPT_CAINFO, "pathto/cacert.pem");

请您检查下面添加两个选项

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
curl_setopt ($ch, CURLOPT_CAINFO, "pathto/cacert.pem");
answer2: 回答2:

Check if below works:

<?PHP

// connect via SSL, but don't check cert
$handle=curl_init('https://www.google.com');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($handle);

echo $c
?>

检查下面的工程:

<?PHP

// connect via SSL, but don't check cert
$handle=curl_init('https://www.google.com');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($handle);

echo $c
?>
php  ssl  curl  google-plus