博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php curl常见错误:SSL错误、bool(false)
阅读量:6548 次
发布时间:2019-06-24

本文共 1628 字,大约阅读时间需要 5 分钟。

在命令行中使用curl调用跳过SSL证书检查的方法,需要的朋友可以参考下。
 
 
症状: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.

转载地址:http://ohedo.baihongyu.com/

你可能感兴趣的文章
HTTP协议实体的基本讲解
查看>>
日志组件logback的介绍及配置使用方法
查看>>
JAVA -Xms -Xmx -XX:PermSize -XX:MaxPermSize 区别
查看>>
R语言包_dplyr_1
查看>>
yii2:引用项目外的文件或类
查看>>
set类型以及其操作
查看>>
进程 线程 协程
查看>>
阿里安卓面试分析: Android应用的闪退(crash)问题跟踪和解析
查看>>
Win10系列:C#应用控件基础19
查看>>
【概念原理】四种SQL事务隔离级别和事务ACID特性
查看>>
js 继承概述
查看>>
Linux命令行常用光标移动快捷键
查看>>
图结构练习——BFS——从起始点到目标点的最短步数(邻接表+BFS)
查看>>
Java笔记16:多线程共享数据
查看>>
JavaStuNote 5
查看>>
经验总结22--抓取HTML数据,HtmlAgilityPack(续)
查看>>
HDU 5360 Hiking(优先队列)2015 Multi-University Training Contest 6
查看>>
Permutation Test 置换检验
查看>>
喵哈哈村的魔法考试 Round #19 (Div.2) 题解
查看>>
添加商品验证商品是否存在的两种实现方式
查看>>