php cURL 需要 CURLOPT_SSL_VERIFYPEER=FALSE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18971983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:36:07  来源:igfitidea点击:

cURL requires CURLOPT_SSL_VERIFYPEER=FALSE

phpcurlsslhttpsssl-certificate

提问by tim peterson

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.

我在本地主机上使用 cURL 的时间最长,突然间我注意到它不再有效,除非我明确设置选项CURLOPT_SSL_VERIFYPEER= FALSE

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.comand https://different-site.com.

我不知道这是如何/何时改变的,但我正在使用 NGINX 和 PHP,我可以验证这不是特定请求主机的特定问题。我收到来自https://site1.com和 的空白回复https://different-site.com

Anyone have any thoughts?

有人有什么想法吗?

回答by tim peterson

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

多亏了 Dave Chen 的建议,我才意识到我一定把证书放错了地方。该问题由 cURL 创建者提供的证书解决(从 Mozilla 中提取):https: //curl.haxx.se/ca/cacert.pem

So after downloading this cacert.pem file into your project, in PHP you can now do this:

因此,在将此 cacert.pem 文件下载到您的项目后,您现在可以在 PHP 中执行以下操作:

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

Alternatively, this can be set globally by adding the following to your php.ini

或者,可以通过将以下内容添加到 php.ini 来全局设置

curl.cainfo=/path/to/cacert.pem

回答by LuisEduardox

If you are using WampServer, notice this:

如果您使用的是 WampServer,请注意:

You must put the absolute pathin CURLOPT_CAINFO, for example:

您必须将绝对路径放在 CURLOPT_CAINFO 中,例如:

curl_setopt ($ch, CURLOPT_CAINFO, 'C:\wamp\www\your-project\cacert.pem')

Don't use relative path: curl_setopt ($ch, CURLOPT_CAINFO, 'cacert.pem') because it doesn't work.

不要使用相对路径: curl_setopt ($ch, CURLOPT_CAINFO, 'cacert.pem')因为它不起作用

回答by dresh

The value for CURLOPT_SSL_VERIFYPEER by default is TRUE as of cURL 7.10.

从 cURL 7.10 开始,默认情况下 CURLOPT_SSL_VERIFYPEER 的值为 TRUE。

Hence you may need to explicitly set it to FALSE to prevent CURL from verifying the certificate.

因此,您可能需要将其显式设置为 FALSE 以防止 CURL 验证证书。