用PHP卷曲SSL错误 [英] SSL error with PHP curl

查看:163
本文介绍了用PHP卷曲SSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好老乡程序员,

我做了HTTPS连接的API。我想,以确保与证书检查API调用。现在,我已经下载了卷曲cacert.pem并放置在此我的文件夹中,但它不工作,给我这个错误:

I'm making an API with a https connection. I want to secure the API call with a certificate check. Now i've downloaded the cacert.pem from curl and placed this in my folder, but it doesn't work and gives me this error:

SSL certificate problem: unable to get local issuer certificate

好吧我真的确保cacert.pem文件位于正确的,但对于你们一些code,我一直在写得到它的工作:

Well i'm really sure that the cacert.pem file is located correctly but for you guys some code that i've been writing to get it working:

 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_POST      ,1);
 curl_setopt($ch, CURLOPT_USERPWD, $this->api_key . ":" . $this->api_secret);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
 curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . "/cacert.pem");
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
 curl_setopt($ch, CURLOPT_POSTFIELDS    ,$post_vars);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,0);
 curl_setopt($ch,CURLOPT_HTTPHEADER,array('Accept: application/json'));
 curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
 $data = curl_exec($ch);

我希望你一些你们都为我的问题的答案,因为我真的不知道很多关于SSL连接。

I hope you some of you guys have an answer for my question because I really don't know much about SSL connections.

在此先感谢!

推荐答案

在作出确认您的证书捆绑是你正在运行脚本的可读性,下一步就是探讨服务器本身。

After having made sure that your certificate bundle is readable by the script you're running, the next step is to investigate the server itself.

如果这是你自己的服务器,很可能是你忘了安装中间证书,即在所颁发的证书,并随附束证书颁发机构之一的人。

If this is your own server, it's likely that you forgot to install the intermediate certificates, i.e. the ones in between the issued certificate and one of the certificate authorities that comes with the bundle.

如果您正在使用自签名证书的工作,你的 cacert.pem 应该包含你正在连接的服务器的公证书;这可以从私有证书生成,概括这里,简称 .CRT 文件。

If you're working with a self-signed certificate, your cacert.pem should contain the public certificate of the server you're connecting to; this can be generated from the private certificate, outlined here, referred to as the .crt file.

这篇关于用PHP卷曲SSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆