http 使用curl发起https请求
来源:互联网 发布:公众号 回复 php 代码 编辑:程序博客网 时间:2024/06/05 10:59
http://www.cnblogs.com/ainiaa/archive/2011/11/08/2241385.html
今天一个同事反映,使用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 本地判别文件
http://curl.haxx.se/ca/cacert.pem
放到 程序文件目录
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)
如果对此感兴趣的话可以参看国外一大神文章。http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
为了防止某天该文章被Q今复制过来。内容如下:
Using cURL in PHP to access HTTPS (SSL/TLS) protected sites
- http 使用curl发起https请求
- http 使用curl发起https请求
- http 使用curl发起https请求
- http 使用curl发起https请求
- http 使用curl发起https请求
- http 使用curl发起https请求
- http 使用curl发起https请求
- 使用cURL发起https请求
- 使用curl发起https请求
- http 使用curl发起https请求 error 60 51
- php使用curl发起http请求
- 发起https和http请求
- 使用http发起请求
- php curl使用代理发起请求
- 使用NSURLSession发起HTTPS网络请求
- PHP curl 模拟http https请求
- php curl请求http和https
- 如何在java中发起http和https请求
- Android异步加载图像小结
- mysql乱码,开发中遇到的问题
- Linux/shell命令的实际应用——netstat查看Port占用
- 使用SQLite存储以及读取Drawable对象
- 【传输层】UDP知识详解
- http 使用curl发起https请求
- HTTP请求远端String和byte[]数据
- MapReduce原理
- C语言调用mysql函数
- Codeforces Problemset 23D(#23 div.1 D)
- Tab切换5种方法
- GridView添加网格线
- POJ 1502 MPI Maelstrom(floyd)#by zh
- redis 源代码之数据结构(1)--链表的实现