PHP头条
热点:

php curl 获取https请求的2种方法


   php curl 获取https请求的2种方法

        这篇文章主要介绍了php curl 获取https请求的2种方法,本文给出设定为不验证证书和host、设定一个正确的证书二种常用做法的代码实例,需要的朋友可以参考下

  今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”

  很明显,验证证书的时候出现了问题。

  使用curl如果想发起的https请求正常的话有2种做法:

  方法一、设定为不验证证书和host。

  在执行curl_exec()之前。设置option

  代码如下:

  $ch = curl_init();

  ......

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

  方法二、设定一个正确的证书。

  本地ssl判别证书太旧,导致链接报错ssl证书不正确。

  我们需要下载新的ssl 本地判别文件

  放到 程序文件目录

  curl 增加下面的配置

  代码如下:

  curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); ;

  curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');

  大功告成

  (本人验证未通过。。。报错信息为:SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed)

www.phpzy.comtrue/php/24538.htmlTechArticlephp curl 获取https请求的2种方法 php curl 获取https请求的2种方法 这篇文章主要介绍了php curl 获取https请求的2种方法,本文给出设定为不验证证书和host、设定一个正确的证书二种常用做法的代...

相关文章

PHP之友评论

今天推荐