症状: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 curl常见错误:SSL错误、bool(false)
2019-12-20 16:10PHP教程网 PHP教程
在命令行中使用curl调用跳过SSL证书检查的方法,需要的朋友可以参考下。
延伸 · 阅读
- 2022-03-10简单谈谈centos7中配置php
- 2022-03-06Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方
- 2022-03-05Nginx配置ssl实现https的全过程记录
- 2022-03-05centos yum php 7.x 无需删除升级的方法
- 2022-03-05Centos7下PHP安装gd库的实例讲解
- 2022-03-03linux环境下安装PHP的OpenSSL扩展的方法讲解
- PHP教程
php eval函数用法 PHP中eval()函数小技巧
本函式可将字符串之中的变量值代入,通常用在处理数据库的数据上 ...
- PHP教程
CodeIgniter记录错误日志的方法全面总结
这篇文章主要介绍了CodeIgniter记录错误日志的方法,详细分析了CodeIgniter框架的文件结构与相应的功能,结合实例分析了CodeIgniter框架记录错误日志的实现技巧...
- PHP教程
Linux平台PHP5.4设置FPM线程数量的方法
这篇文章主要介绍了Linux平台PHP5.4设置FPM线程数量的方法,较为详细的分析了Linux平台php5.4设置FPM的相关参数、功能及使用技巧,需要的朋友可以参考下...
- PHP教程
php curl_init函数用法
使用PHP的cURL库可以简单和有效地去抓网页。你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了 ...
- PHP教程
PHP面向对象详解(三)
这篇文章主要介绍了PHP面向对象详解(三) 的相关资料,需要的朋友可以参考下...
- PHP教程
php比较两个指定的日期的实例讲解
在本篇文章里小编给大家整理了一篇关于php如何比较两个指定的日期的相关知识点内容,有需要的朋友们可以参考下。...
- PHP教程
PHP编程中的Session阻塞问题与解决方法分析
这篇文章主要介绍了PHP编程中的Session阻塞问题与解决方法,简单分析了php session阻塞的原理、原因与简单解决方法,需要的朋友可以参考下...
- PHP教程
laravel 输出最后执行sql 附:whereIn的使用方法
今天小编就为大家分享一篇laravel 输出最后执行sql 附:whereIn的使用方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...