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面向对象的使用教程 简单数据库连接
Nov 25 PHP
php 5.3.5安装memcache注意事项小结
Apr 12 PHP
php在项目中寻找代码的坏味道(综艺命名)
Jul 19 PHP
destoon复制新模块的方法
Jun 21 PHP
PHP将HTML转换成文本的实现代码
Jan 21 PHP
php中删除数组的第一个元素和最后一个元素的函数
Mar 07 PHP
yii实现model添加默认值的方法(2种方法)
Jan 06 PHP
Symfony2在Nginx下的配置方法图文教程
Feb 04 PHP
php简单复制文件的方法
May 09 PHP
基于ThinkPHP5框架使用QueryList爬取并存入mysql数据库操作示例
May 25 PHP
PHP封装cURL工具类与应用示例
Jul 01 PHP
THINKPHP-Apache服务器中使用Alias虚拟目录URL重写 隐藏index.php
Mar 09 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
超外差式晶体管收音机的组装与统调
2021/03/01 无线电
PHP使用feof()函数读文件的方法
2014/11/07 PHP
PHP实现的DES加密解密实例代码
2016/04/06 PHP
浅谈javascript的数据类型检测
2010/07/10 Javascript
js弹出模式对话框,并接收回传值的方法
2013/03/12 Javascript
使图片旋转的3种解决方案
2013/11/21 Javascript
jQuery中常用的遍历函数用法实例总结
2015/09/01 Javascript
使用JavaScript为Kindeditor自定义按钮增加Audio标签
2016/03/18 Javascript
jquery 键盘事件的使用方法详解
2017/09/13 jQuery
javascript高仿热血传奇游戏实现代码
2018/02/22 Javascript
5分钟学会Vue动画效果(小结)
2018/07/21 Javascript
详解vue移动端项目代码拆分记录
2019/03/15 Javascript
node.js中 redis 的安装和基本操作示例
2020/02/10 Javascript
如何检测JavaScript中的死循环示例详解
2020/08/30 Javascript
[00:43]2016完美“圣”典风云人物:单车宣传片
2016/12/02 DOTA
[01:14:30]TNC vs VG 2019国际邀请赛淘汰赛 胜者组赛BO3 第二场 8.20.mp4
2019/08/22 DOTA
使用Python写一个贪吃蛇游戏实例代码
2017/08/21 Python
Flask解决跨域的问题示例代码
2018/02/12 Python
python flask中静态文件的管理方法
2018/03/20 Python
Python进阶之全面解读高级特性之切片
2019/02/19 Python
python爬取微信公众号文章的方法
2019/02/26 Python
python代码编写计算器小程序
2020/03/30 Python
python Kmeans算法原理深入解析
2019/08/23 Python
Python上下文管理器全实例详解
2019/11/12 Python
python 子类调用父类的构造函数实例
2020/03/12 Python
Django haystack实现全文搜索代码示例
2020/11/28 Python
浅析border-radius如何兼容IE
2016/04/19 HTML / CSS
J2EE系统只能是基于web
2015/09/08 面试题
房产转让协议书
2014/04/11 职场文书
在职党员进社区活动总结
2014/07/05 职场文书
领导班子四风对照检查材料范文
2014/09/27 职场文书
乡镇群众路线整改落实情况汇报
2014/10/28 职场文书
幼师自荐信范文
2015/03/06 职场文书
读《儒林外史》有感:少一些功利,多一些真诚
2020/01/19 职场文书
分布式锁为什么要选择Zookeeper而不是Redis?看完这篇你就明白了
2021/05/21 Redis
python 算法题——快乐数的多种解法
2021/05/27 Python