php curl常见错误:SSL错误、bool(false)


Posted in PHP onDecember 28, 2011

症状:php curl调用https出错
排查方法:在命令行中使用curl调用试试。
原因:服务器所在机房无法验证SSL证书。
解决办法:跳过SSL证书检查。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

症状:php curl调用curl_exec返回bool(false),命令行curl调用正常。
排查方法:
var_dump(curl_error($ch));
返回:
string(23) "Empty reply from server"
再排查:
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
返回:
HTTP/1.1 100 Continue
Connection: close
原因:php curl接收到HTTP 100就结束了,应该继续接收HTTP 200
解决方案:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

PHP and cURL: Disabling 100-continue header
Published June 15th, 2006
I've been using cURL (through PHP) to build a sort of proxy for a project I'm working on. I need to parse the returned headers (to recover the HTTP status), so had included a very simple script to do so. It had worked fine in the past, but for some reason barfed in this case. A closer look at what was being returned revealed that for some reason, Apache was prepending the ‘normal' headers with an extra response header:

HTTP/1.1 100 Continue

HTTP/1.1 200 OK Date: Fri, 09 Jun 2006 15:23:42 GMT
Server: Apache
...A bit of Googling revealed that this was to do with a header that cURL sends by default:

Expect: 100-continue

…which in turns tells Apache to send the extra header. I poked around a fair bit but couldn't quite find a workable solution short of manually removing the header in PHP, which seemed a bit clumsy. Finally, on a hunch I tried this:

curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

…which basically overrides the original ‘Expect:' header with an empty one.

Hope this helps someone.

PHP 相关文章推荐
在同一窗体中使用PHP来处理多个提交任务
Oct 09 PHP
用ADODB来让PHP操作ACCESS数据库的方法
Dec 31 PHP
浅谈web上存漏洞及原理分析、防范方法(文件名检测漏洞)
Jun 29 PHP
PHP实现的博客欢迎提示功能(很特别哦)
Jun 05 PHP
PHP将进程作为守护进程的方法
Mar 19 PHP
php中Snoopy类用法实例
Jun 19 PHP
PHP7正式版测试,性能惊艳!
Dec 08 PHP
PHP中strnatcmp()函数“自然排序算法”进行字符串比较用法分析(对比strcmp函数)
Jan 07 PHP
php PDO异常处理详解
Nov 20 PHP
PHP多进程通信-消息队列使用
Mar 08 PHP
gearman中worker常驻后台,导致MySQL server has gone away的解决方法
Feb 27 PHP
ThinkPHP5与单元测试PHPUnit使用详解
Feb 23 PHP
PHP+Ajax异步通讯实现用户名邮箱验证是否已注册( 2种方法实现)
Dec 28 #PHP
shopex主机报错误请求解决方案(No such file or directory)
Dec 27 #PHP
PHP写UltraEdit插件脚本实现方法
Dec 26 #PHP
url decode problem 解决方法
Dec 26 #PHP
最新用php获取谷歌PR值算法,附上php查询PR值代码示例
Dec 25 #PHP
匹配csdn用户数据库与官方用户的重合度并将重叠部分的用户筛选出来
Dec 25 #PHP
php操作JSON格式数据的实现代码
Dec 24 #PHP
You might like
ajax+php打造进度条 readyState各状态
2010/03/20 PHP
PHP中“简单工厂模式”实例代码讲解
2012/09/04 PHP
用PHP实现弹出消息提示框的两种方法
2013/12/17 PHP
PHP后端银联支付及退款实例代码
2017/06/23 PHP
实例化php类时传参的方法分析
2020/06/05 PHP
dojo 之基础篇
2007/03/24 Javascript
js小技巧--自动隐藏红叉叉
2007/08/13 Javascript
javascript 事件处理程序介绍
2012/06/27 Javascript
js分页工具实例
2015/01/28 Javascript
jQuery知识点整理
2015/01/30 Javascript
解决jquery实现的radio重新选中的问题
2015/07/03 Javascript
javascript判断回文数详解及实现代码
2017/02/03 Javascript
基于JQuery及AJAX实现名人名言随机生成器
2017/02/10 Javascript
Bootstrap table右键功能实现方法
2017/02/20 Javascript
JS仿Base.js实现的继承示例
2017/04/07 Javascript
js数字滑动时钟的简单实现(示例讲解)
2017/08/14 Javascript
vue-以文件流-blob-的形式-下载-导出文件操作
2020/08/07 Javascript
Python实现周期性抓取网页内容的方法
2015/11/04 Python
python扫描proxy并获取可用代理ip的实例
2017/08/07 Python
Python拼接微信好友头像大图的实现方法
2018/08/01 Python
python机器学习包mlxtend的安装和配置详解
2019/08/21 Python
Python3 合并二叉树的实现
2019/09/30 Python
在pandas中遍历DataFrame行的实现方法
2019/10/23 Python
Python建造者模式案例运行原理解析
2020/06/29 Python
解决python 虚拟环境删除包无法加载的问题
2020/07/13 Python
Python获取excel内容及相关操作代码实例
2020/08/10 Python
CSS3毛玻璃效果(blur)有白边问题的解决方法
2016/11/15 HTML / CSS
美国乡村商店:Plow & Hearth
2016/09/12 全球购物
G-Form护具官方网站:美国运动保护装备
2019/09/04 全球购物
经济国贸专业求职信
2014/06/18 职场文书
个人委托书
2014/07/31 职场文书
英文演讲稿开场白
2014/08/25 职场文书
会议通知格式范文
2015/04/15 职场文书
经费申请报告
2015/05/15 职场文书
公安纪律作风整顿心得体会
2016/01/23 职场文书
2019年最新证婚词精选集!
2019/06/28 职场文书