php curl常见错误:SSL错误、bool(false)
2015-01-24信息快讯网
排查方法:在命令行中使用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 Global变量定义当前页面的全局变量实现探讨
php htmlspecialchars()与shtmlspecialchars()函数的深入分析
php set_time_limit()函数的使用详解
fetchAll()与mysql_fetch_array()的区别详解
浅谈php serialize()与unserialize()的用法
PHP中__get()和__set()的用法实例详解
CURL的学习和应用(附多线程实现)
基于session_unset与session_destroy的区别详解
基于PHP CURL获取邮箱地址的详解
基于Discuz security.inc.php代码的深入分析
php curl的深入解析
setcookie中Cannot modify header information-headers already sent by错误的解决方法详解
PHP闭包(Closure)使用详解
基于curl数据采集之正则处理函数get_matches的使用
基于curl数据采集之单页面并行采集函数get_htmls的使用
PHP防CC攻击实现代码
PHP+Ajax异步通讯实现用户名邮箱验证是否已注册( 2种方法实现)
url decode problem 解决方法
在PHP中利用wsdl创建标准webservice的实现代码
php urlencode()与urldecode()函数字符编码原理详解
php数组函数序列之array_intersect() 返回两个或多个数组的交集数组
php空间不支持socket但支持curl时recaptcha的用法
php获取远程图片的两种 CURL方式和sockets方式获取远程图片
php数组函数序列之array_search()- 按元素值返回键名
PHP隐形一句话后门,和ThinkPHP框架加密码程序(base64_decode)
php数组函数序列之array_values() 获取数组元素值的函数与方法
php数组函数序列 之array_count_values() 统计数组中所有值出现的次数函数
PHP 小心urldecode引发的SQL注入漏洞
Session保存到数据库的php类分享
php下利用curl判断远程文件是否存在的实现代码
Sorting Array Values in PHP(数组排序)
php中使用Curl、socket、file_get_contents三种方法POST提交数据
判断Keep-Alive模式的HTTP请求的结束的实现代码
linux下为php添加curl扩展的方法
php自定义函数call_user_func和call_user_func_array详解