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与MySQL交互使用详解
Oct 09 PHP
PHP 模拟$_PUT实现代码
Mar 15 PHP
PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
Aug 22 PHP
PHP输入流php://input介绍
Sep 18 PHP
有关phpmailer的详细介绍及使用方法
Jan 28 PHP
PHP实现的购物车类实例
Jun 17 PHP
php实现头像上传预览功能
Apr 27 PHP
Laravel 5.5 的自定义验证对象/类示例代码详解
Aug 29 PHP
win10 apache配置虚拟主机后localhost无法使用的解决方法
Jan 27 PHP
PHP通过curl获取接口URL的数据方法
May 31 PHP
Laravel项目中timeAgo字段语言转换的改善方法示例
Sep 16 PHP
laravel框架实现敏感词汇过滤功能示例
Feb 15 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 Document 代码注释规范
2009/04/13 PHP
php数组分页实现方法
2016/04/30 PHP
Win10 下安装配置IIS + MySQL + nginx + php7.1.7
2017/08/04 PHP
laravel框架上传图片实现实时预览功能
2019/10/14 PHP
基于prototype的validation.js发布2.3.4新版本,让你彻底脱离表单验证的烦恼
2006/12/06 Javascript
javascript判断网页是关闭还是刷新
2015/09/12 Javascript
通过设置CSS中的position属性来固定层的位置
2015/12/14 Javascript
JSP基于Bootstrap分页显示实例解析
2016/06/12 Javascript
Java  Spring 事务回滚详解
2016/10/17 Javascript
bootstrap datetimepicker实现秒钟选择下拉框
2017/01/05 Javascript
js中作用域的实例解析
2017/03/16 Javascript
将angular.js项目整合到.net mvc中的方法详解
2017/06/29 Javascript
使用原生js+canvas实现模拟心电图的实例
2017/09/20 Javascript
JS重学系列之聊聊new操作符
2019/03/04 Javascript
解决vue侦听器watch,调用this时出现undefined的问题
2020/10/30 Javascript
Python中的字典与成员运算符初步探究
2015/10/13 Python
利用python批量检查网站的可用性
2016/09/09 Python
python如何使用jt400.jar包代码实例
2019/12/20 Python
解决Keras 中加入lambda层无法正常载入模型问题
2020/06/16 Python
matplotlib基础绘图命令之errorbar的使用
2020/08/13 Python
python3 os进行嵌套操作的实例讲解
2020/11/19 Python
Python爬虫之Selenium实现窗口截图
2020/12/04 Python
中秋节超市促销方案
2014/01/30 职场文书
数控技术学生的自我评价
2014/02/15 职场文书
《诺贝尔》教学反思
2014/02/17 职场文书
知名企业招聘广告词大全
2014/03/18 职场文书
好的促销活动方案
2014/08/21 职场文书
行政工作试用期自我评价
2014/09/14 职场文书
2014年汽车销售工作总结
2014/12/01 职场文书
个人合作协议范本
2015/08/06 职场文书
2016年大学生社会实践心得体会
2015/10/09 职场文书
房地产置业顾问工作总结
2015/10/23 职场文书
企业管理不到位检讨书
2019/06/27 职场文书
创业计划书之熟食店
2019/10/16 职场文书
深入解析Apache Hudi内核文件标记机制
2022/03/31 Servers
Mysql数据库事务的脏读幻读及不可重复读详解
2022/05/30 MySQL