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 相关文章推荐
mysql 搜索之简单应用
Apr 27 PHP
mysql5的sql文件导入到mysql4的方法
Oct 19 PHP
在PHP中检查PHP文件是否有语法错误的方法
Dec 23 PHP
php中使用$_REQUEST需要注意的一个问题
May 02 PHP
PHP SPL标准库之数据结构栈(SplStack)介绍
May 12 PHP
php设计模式之单例模式代码
Jun 11 PHP
PHP简单读取PDF页数的实现方法
Jul 21 PHP
PHP排序二叉树基本功能实现方法示例
May 26 PHP
PHP命令Command模式用法实例分析
Aug 08 PHP
PHP实现基于状态的责任链审批模式详解
May 31 PHP
PHP7.3.10编译安装教程
Oct 08 PHP
php如何实现数据库的备份和恢复
Nov 30 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
php格式化电话号码的方法
2015/04/24 PHP
使用PHP开发留言板功能
2019/11/19 PHP
FLASH 广告之外的链接
2008/12/16 Javascript
Javascript实现颜色rgb与16进制转换的方法
2015/04/18 Javascript
jQuery实现的类似淘宝网站搜索框样式代码分享
2015/08/24 Javascript
js实现一个可以兼容PC端和移动端的div拖动效果实例
2016/12/09 Javascript
AngularJS实现表格的增删改查(仅限前端)
2017/07/04 Javascript
webpack vue 项目打包生成的文件,资源文件报404问题的修复方法(总结篇)
2018/01/09 Javascript
vue移动UI框架滑动加载数据的方法
2018/03/12 Javascript
微信小程序实现打卡日历功能
2020/09/21 Javascript
JavaScript递归函数定义与用法实例分析
2019/01/24 Javascript
layui radio单选限制下一个radio单选的实例
2019/09/03 Javascript
javascript实现简易数码时钟
2020/03/30 Javascript
JS script脚本中async和defer区别详解
2020/06/24 Javascript
vue接通后端api以及部署到服务器操作
2020/08/13 Javascript
Python实现方便使用的级联进度信息实例
2015/05/05 Python
Python实现查找系统盘中需要找的字符
2015/07/14 Python
python 使用get_argument获取url query参数
2017/04/28 Python
深入浅析Python中的yield关键字
2018/01/24 Python
Python中存取文件的4种不同操作
2018/07/02 Python
Python之lambda匿名函数及map和filter的用法
2019/03/05 Python
Pandas透视表(pivot_table)详解
2019/07/22 Python
利用pyecharts实现地图可视化的例子
2019/08/12 Python
python中如何实现将数据分成训练集与测试集的方法
2019/09/13 Python
python判断链表是否有环的实例代码
2020/01/31 Python
Django查询优化及ajax编码格式原理解析
2020/03/25 Python
python实现暗通道去雾算法的示例
2020/09/27 Python
澳大利亚香水在线:Price Rite Mart
2017/12/28 全球购物
node中使用shell脚本的方法步骤
2021/03/23 Javascript
酒店个人培训自我鉴定
2013/12/11 职场文书
会计大学生职业生涯规划书范文
2014/01/13 职场文书
早读迟到检讨书
2014/01/24 职场文书
道路交通事故人身损害赔偿协议书
2014/11/19 职场文书
碧霞祠导游词
2015/02/09 职场文书
毕业论文指导老师意见
2015/06/04 职场文书
八年级作文之感恩
2019/11/22 职场文书