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
PHP计划任务、定时执行任务的实现代码
Apr 23 PHP
推荐25款php中非常有用的类库
Sep 29 PHP
PHP实现定时执行任务的方法
Oct 05 PHP
分享自定义的几个PHP功能函数
Apr 15 PHP
php基于Snoopy解析网页html的方法
Jul 09 PHP
8个必备的PHP功能开发
Oct 02 PHP
PHP中PDO连接数据库中各种DNS设置方法小结
May 13 PHP
Yii2针对游客、用户防范规则和限制的解决方法分析
Oct 08 PHP
PHP封装的非对称加密RSA算法示例
May 28 PHP
PHP如何使用array_unshift()在数组开头插入元素
Sep 01 PHP
laravel入门知识点整理
Sep 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
大师制作的中短波矿石收音机
2020/04/02 无线电
利用PHP实现智能文件类型检测的实现代码
2011/08/02 PHP
php多次include后导致全局变量global失效的解决方法
2015/02/28 PHP
php mailer类调用远程SMTP服务器发送邮件实现方法
2016/03/04 PHP
关于php支持的协议与封装协议总结(推荐)
2017/11/17 PHP
PHP设计模式之装饰器模式实例详解
2018/02/07 PHP
购物车实现的几种方式优缺点对比
2018/05/02 PHP
javascript入门·图片对象(无刷新变换图片)\滚动图像
2007/10/01 Javascript
Array.prototype 的泛型应用分析
2010/04/30 Javascript
如何让你的Lightbox支持滚轮缩放及Base64图片
2014/12/04 Javascript
jquery 插件实现多行文本框[textarea]自动高度
2015/03/04 Javascript
javascript replace()第二个参数为函数时的参数用法
2016/12/26 Javascript
vue3.0 CLI - 2.1 -  component 组件入门教程
2018/09/14 Javascript
JavaScript闭包相关知识解析
2019/10/19 Javascript
json.stringify()与json.parse()的区别以及用处
2021/01/25 Javascript
[44:40]Spirit vs Navi Supermajor小组赛 A组败者组第一轮 BO3 第一场 6.2
2018/06/03 DOTA
matplotlib.pyplot画图 图片的二进制流的获取方法
2018/05/24 Python
Python+selenium实现自动循环扔QQ邮箱漂流瓶
2018/05/29 Python
python判断数字是否是超级素数幂
2018/09/27 Python
Python基础之条件控制操作示例【if语句】
2019/03/23 Python
Python pyautogui模块实现鼠标键盘自动化方法详解
2020/02/17 Python
python pandas移动窗口函数rolling的用法
2020/02/29 Python
TensorFlow tf.nn.softmax_cross_entropy_with_logits的用法
2020/04/19 Python
python实现PolynomialFeatures多项式的方法
2021/01/06 Python
你正在寻找的CSS3 动画技术
2011/07/27 HTML / CSS
CSS3让登陆面板3D旋转起来
2016/05/03 HTML / CSS
几个解决兼容IE6\7\8不支持html5标签的几个方法
2013/01/07 HTML / CSS
iPhoneX安全区域(Safe Area)底部小黑条在微信小程序和H5的屏幕适配
2020/04/08 HTML / CSS
纽约著名的服装辅料来源:M&J Trimming
2017/07/26 全球购物
美国伊甸园兄弟种子公司:Eden Brothers
2018/07/01 全球购物
计算机操作自荐信
2013/12/07 职场文书
医学生个人求职信范文
2014/02/07 职场文书
公司应聘求职信
2014/06/21 职场文书
给老婆的保证书怎么写
2015/05/08 职场文书
运动会100米广播稿
2015/08/19 职场文书
社交电商模式的兴起:这些新的商机千万别错过
2019/07/26 职场文书