cURL中的SSL证书错误 [英] SSL certificate error in cURL

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

问题描述

事实

我在Win 10笔记本电脑上拥有Apache / 2.4.27(Win64)PHP / 7.2.0beta3。我想实现cURL。这是我的代码

I have Apache/2.4.27 (Win64) PHP/7.2.0beta3 on Win 10 laptop. I want to implement cURL. This is my code

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'https://www.youtube.com');
curl_exec($curl);

if (curl_errno ( $curl )) {
    echo curl_error ( $curl );
    curl_close ( $curl );
}

产生错误 SSL证书问题:无法获得本地颁发者证书。所以我从 https://curl.haxx.se/ca/cacert.pem。取了cacert.pem文件,把它放在PHP文件夹中并编辑 php.ini 文件,如
curl.cainfo = C :PHP / EXT / cacert.pem

that generates the error SSL certificate problem: unable to get local issuer certificate. So I downloaded certificates from https://curl.haxx.se/ca/cacert.pem. Took the cacert.pem file, put it in the PHP folder and edited the php.ini file like this curl.cainfo = C:php/ext/cacert.pem.

问题

现在我收到此错误错误设置证书验证位置:CAfile:C:php / ext / cacert.pem CApath:none 。我用谷歌搜索,我找到的唯一解决方案是我必须从我想要的网站下载 .crt 文件并将其包含在我的cURL中,如 curl_setopt($ curl,CURLOPT_CAINFO,C:/wamp64/www/GIAG2.crt);

Now I get this error error setting certificate verify locations: CAfile: C:php/ext/cacert.pem CApath: none. I googled and the only solution I found is that I have to download the .crt file from the site I want to cURL and include it in my cURL like curl_setopt($curl, CURLOPT_CAINFO, "C:/wamp64/www/GIAG2.crt");.

问题1.1
我不知道如何下载 .crt 文件,所以我可以将它包含在我的代码中,如上例所示。

Problem 1.1 : I dont know how to download the .crt file so I can include it in my code, like the above example.

问题1.2 :这不是一个通用解决方案,我想设置我的证书,以便我不必下载不同的不同网站的证书。

Problem 1.2 : That is not a "universal" solution, I want to set my certificates in such way that I dont have to download different certificates for different site.

谢谢

推荐答案

当前的CA cURL 提供的证书摘录包含签署Google的CA证书的GeoTrust Global CA证书颁发机构。反过来签署YouTube的证书,所以你使用你的文件应该没有问题。

The current CA Cert extracts provided by cURL contain the GeoTrust Global CA certificate authority which signed Google's CA cert which in turn signs YouTube's cert, so you should have no problem using the file you have.

根据上一个错误,看起来问题是因为你错过了 / C:之后。消息错误设置证书验证位置表示它无法打开或读取 curl.cainfo 指定的文件,因此它根本没有找到任何证书。

Based on the last error, it looks like the problem is because you were missing the / after C:. The message error setting certificate verify locations means that it couldn't open or read the file specified by curl.cainfo so it's not finding any certs at all.

如果你将 C:php / ext / cacert.pem 更改为 C:/php/ext/cacert.pem 它应该能够正确读取CA文件,然后正确验证网站。

If you change C:php/ext/cacert.pem to C:/php/ext/cacert.pem it should be able to read the CA file correctly and then verify the site properly.

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

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