http 使用curl发起https请求
今天一个同事反映,使用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
From PHP, you can access the useful cURL Library (libcurl) to make requests to URLs using a variety of protocols such as HTTP, FTP, LDAP and even Gopher. (If you’ve spent time on the *nix command line, most environments also have the curl
command available that uses the libcurl library)
In practice, however, the most commonly-used protocol tends to be HTTP, especially when using PHP for server-to-server communication. Typically this involves accessing another web server as part of a web service call, using some method such as XML-RPC or REST to query a resource. For example, Delicious offers a HTTP-based API to manipulate and read a user’s posts. However, when trying to access a HTTPS resource (such as the delicious API), there’s a little more configuration you have to do before you can get cURL working right in PHP.
The problem
// Initialize session and set URL. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); // Set so curl_exec returns the result instead of outputting it. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Get the response and close the channel. $response = curl_exec($ch); curl_close($ch);
If $url
points toward an HTTPS resource, you’re likely to encounter an error like the one below:
Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
The quick fix
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
The proper fix
Then click on “View Certificate”:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/CAcerts/BuiltinObjectToken-EquifaxSecureCA.crt");
The other option I’ve included, CURLOPT_SSL_VERIFYHOST
can be set to the following integer values:
- 0: Don’t check the common name (CN) attribute
- 1: Check that the common name attribute at least exists
- 2: Check that the common name exists and that it matches the host name of the server
More information
转载于:https://www.cnblogs.com/ainiaa/archive/2011/11/08/2241385.html
http 使用curl发起https请求相关推荐
- 用curl发起https请求
使用curl发起https请求 使用curl如果想发起的https请求正常的话有2种做法: 方法一.设定为不验证证书和host. 在执行curl_exec()之前.设置option $ch = cur ...
- http 使用curl发起https请求 error 60 51
curl_setopt换成 curl_easy_setopt cacert.pem路径换成字符串 CURLOPT_SSL_VERIFYHOST 解决error 51 大概7.28版本后要设置2,不是 ...
- WAMP安装curl扩展并发起https请求
wamp安装curl扩展的方法: http://blog.csdn.net/superuser007/article/details/5781095 安装出现 PHP Extension " ...
- java用HttpURLConnection发起HTTPS请求并跳过SSL证书,解决:unable to find valid certification path to requested targ
java用HttpURLConnection发起HTTPS请求并跳过SSL证书 问题出现:unable to find valid certification path to requested ta ...
- Shell脚本curl发起http请求并保存到文件/追加到已有文件
1.Shell脚本curl发起http请求,保存到文件 #从nacos配置中心拉取配置数据 #!/bin/bash RESULT=$(curl -s "http://localhost:88 ...
- linux抓post命令,Linux 使用curl发起post请求的4个常用方式
引言 cURL是一种命令行实用程序,用于使用一种受支持的协议,从远程服务器传输数据,或将数据传输到远程服务器.默认情况下,已安装在macOS和大多数Linux发行版上. 开发人员可以使用cURL来测试 ...
- php curl模拟https请求
https请求(支持GET和POST) function http_request($url,$data = null){$curl = curl_init();curl_setopt($curl, ...
- 使用proxy转发post请求_3分钟短文 | Linux 使用curl发起post请求的4个常用方式
引言 cURL是一种命令行实用程序,用于使用一种受支持的协议,从远程服务器传输数据,或将数据传输到远程服务器.默认情况下,已安装在macOS和大多数Linux发行版上. 开发人员可以使用cURL来测试 ...
- php curl 发送https请求失败,php的curl扩展无法发起https请求
很奇怪的是,file_get_content函数可以对https地址发起请求并且收到响应报文,但是curl就不可以,这是什么原因呢?我已经安装了openssl扩展. function fetch($u ...
最新文章
- 虚拟光驱xp版32位_001只有200M的WIN732位的系统复活你的老爷机
- 解决TreeView中使用JavaScript完成CheckBox全选的办法
- 用typescript开发koa2的二三事
- struts1,struts2,springMVC对比
- hdu2648 Shopping-map容器
- mysql+ubunt+绿色安装_Mysql在ubuntu18上的安装及简单使用
- ios assetlibrary
- jpadao层继承什么_实木复合地板特点是什么
- 哈夫曼树以及哈夫曼编码python
- mysql中explain使用
- Packet Tracer 5.0实验(二) 交换机的Telnet远程登录设置
- android模糊搜索文件,模糊搜索_八门神器教程|安卓八门神器怎么用图文教程__单机攻略_跑跑车单机游戏网...
- 服务器系统上1068错误,一个backup exec 2012的真实故障案例,服务无法启动1068
- R语言——双因素方差分析
- CAD打断线条的快捷键是什么?CAD打断线条教程
- POI - 读取Excel2003、Excel2007的兼容性问题
- C++中的常用函数例如for_each、accumulate、unique等
- 大疆无人机飞控软件介绍
- kitty终端使用笔记
- USB摄像头预览识别二维码
热门文章
- 计算输入序列能组成三角形的个数
- sharepoint2013以其他用户身份登录
- poj 1067 取石子游戏(博弈+威佐夫博奕(Wythoff Game))
- (转)《AS3 Expert》动态语言的基石:函数闭包
- 在VMWare上安装Win3.2
- 用ASP创建MDaemon用户
- QTCreator使用MSVC编译开发配置问题、VS2015开发qt问题
- CyUSB.dll的调用经验介绍
- IOS之Masonry约束的使用
- ap drawing 课件_ILITEK TP AP introduction.ppt