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 相关文章推荐
简单的页面缓冲技术
Oct 09 PHP
cmd下运行php脚本
Nov 25 PHP
使用PHP生成二维码的两种方法(带logo图像)
Mar 14 PHP
从PHP的源码中深入了解stdClass类
Apr 18 PHP
PHP实现采集抓取淘宝网单个商品信息
Jan 08 PHP
PHP三种方式实现链式操作详解
Jan 21 PHP
PHP中函数gzuncompress无法使用的解决方法
Mar 02 PHP
PHP实现的简单适配器模式示例
Jun 22 PHP
php5.5使用PHPMailer-5.2发送邮件的完整步骤
Oct 14 PHP
浅谈PHP匿名函数和闭包
Mar 08 PHP
Laravel框架下载,安装及路由操作图文详解
Dec 04 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
Mar 04 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 字符串分割和比较
2009/10/06 PHP
java微信开发之上传下载多媒体文件
2016/06/24 PHP
js以对象为索引的关联数组
2010/07/04 Javascript
jQuery中parentsUntil()方法用法实例
2015/01/07 Javascript
jQuery使用之设置元素样式用法实例
2015/01/19 Javascript
小白谈谈对JS原型链的理解
2016/05/03 Javascript
Javascript学习之谈谈JS的全局变量跟局部变量(推荐)
2016/08/28 Javascript
js canvas实现擦除效果示例代码
2017/04/26 Javascript
Node.js实现用户评论社区功能(体验前后端开发的乐趣)
2019/05/09 Javascript
layui使用templet格式化表格数据的方法
2019/09/16 Javascript
微信小程序后端(java)开发流程的详细步骤
2019/11/13 Javascript
怎么理解wx.navigateTo的events参数使用详情
2020/05/18 Javascript
解决vue addRoutes不生效问题
2020/08/04 Javascript
[02:19]2014DOTA2国际邀请赛 专访820少年们一起去追梦吧
2014/07/14 DOTA
使用python实现strcmp函数功能示例
2014/03/25 Python
Python中的yield浅析
2014/06/16 Python
python比较两个列表大小的方法
2015/07/11 Python
遗传算法之Python实现代码
2017/10/10 Python
python语言中with as的用法使用详解
2018/02/23 Python
Python-OpenCV基本操作方法详解
2018/04/02 Python
Python中常用的高阶函数实例详解
2020/02/21 Python
python使用Geany编辑器配置方法
2020/02/21 Python
tensorflow使用L2 regularization正则化修正overfitting过拟合方式
2020/05/22 Python
HTTP状态码详解
2021/03/18 杂记
HTML页面中添加Canvas标签示例
2015/01/01 HTML / CSS
为什么要用EJB
2014/04/17 面试题
学前教育求职自荐信范文
2013/12/25 职场文书
幼儿教育感言
2014/02/05 职场文书
酒店端午节促销方案
2014/02/18 职场文书
行政管理毕业生自荐信
2014/02/24 职场文书
股份转让协议书
2014/04/12 职场文书
考博专家推荐信
2014/05/10 职场文书
2014年工商所工作总结
2014/12/09 职场文书
民事诉讼代理词
2015/05/25 职场文书
《文化苦旅》读后感:阅读,让人诗意地栖居在大地上
2019/12/24 职场文书
使用pytorch实现线性回归
2021/04/11 Python