cURL 需要 CURLOPT_SSL_VERIFYPEER=FALSE [英] cURL requires CURLOPT_SSL_VERIFYPEER=FALSE
问题描述
我在本地主机上使用 cURL 的时间最长,突然间我注意到它不再起作用,除非我明确设置选项 CURLOPT_SSL_VERIFYPEER
=FALSE
.
I was using cURL on my localhost for the longest time and all the sudden I noticed it no longer works unless I explictly set the option, CURLOPT_SSL_VERIFYPEER
=FALSE
.
我不知道这是如何/何时改变的,但我正在使用 NGINX 和 PHP,我可以验证这不是特定请求主机的特定问题.我收到来自 https://site1.com
和 https://different-site.com
的空白回复.
I have no idea how/when this changed but I'm using NGINX and PHP and I can verify that this is not a specific issue to a specific requested host. I'm getting blank responses from https://site1.com
and https://different-site.com
.
有人有什么想法吗?
推荐答案
感谢 Dave Chen 的建议,我意识到我一定把证书放错了地方.该问题由 cURL 创建者提供的证书解决(从 Mozilla 中提取):https://curl.haxx.se/ca/cacert.pem
Thanks to Dave Chen's suggestions, I realized I must have misplaced my certificate. The problem is solved by this certificate which is provided by the cURL creator (extracted from Mozilla): https://curl.haxx.se/ca/cacert.pem
因此,在将此 cacert.pem 文件下载到您的项目后,您现在可以在 PHP 中执行以下操作:
So after downloading this cacert.pem file into your project, in PHP you can now do this:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");
或者,可以通过在 php.ini 中添加以下内容来全局设置
Alternatively, this can be set globally by adding the following to your php.ini
curl.cainfo=/path/to/cacert.pem
这篇关于cURL 需要 CURLOPT_SSL_VERIFYPEER=FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!