php curl常見錯(cuò)誤:SSL錯(cuò)誤、bool(false)
更新時(shí)間:2011年12月28日 21:42:00 作者:
在命令行中使用curl調(diào)用跳過SSL證書檢查的方法,需要的朋友可以參考下。
癥狀:php curl調(diào)用https出錯(cuò)
排查方法:在命令行中使用curl調(diào)用試試。
原因:服務(wù)器所在機(jī)房無(wú)法驗(yàn)證SSL證書。
解決辦法:跳過SSL證書檢查。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
癥狀:php curl調(diào)用curl_exec返回bool(false),命令行curl調(diào)用正常。
排查方法:
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就結(jié)束了,應(yīng)該繼續(xù)接收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.
排查方法:在命令行中使用curl調(diào)用試試。
原因:服務(wù)器所在機(jī)房無(wú)法驗(yàn)證SSL證書。
解決辦法:跳過SSL證書檢查。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
癥狀:php curl調(diào)用curl_exec返回bool(false),命令行curl調(diào)用正常。
排查方法:
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就結(jié)束了,應(yīng)該繼續(xù)接收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.
相關(guān)文章
PHP 一個(gè)頁(yè)面執(zhí)行時(shí)間類代碼
PHP教程之一個(gè)頁(yè)面執(zhí)行時(shí)間類,需要的朋友可以參考下2010-03-03非常精妙的PHP遞歸調(diào)用與靜態(tài)變量使用
在PHP編程中,遞歸調(diào)用常常與靜態(tài)變量使用。靜態(tài)變量的含義可以參考PHP手冊(cè).希望下面的代碼,會(huì)更有利于對(duì)遞歸以及靜態(tài)變量的理解2012-12-12解析如何去掉CodeIgniter URL中的index.php
本篇文章是對(duì)如何去掉CodeIgniter URL中index.php的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06win10 apache配置虛擬主機(jī)后localhost無(wú)法使用的解決方法
這篇文章主要為大家詳細(xì)介紹了win10 apache配置虛擬主機(jī)后localhost無(wú)法使用的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01詳解PHP版本兼容之openssl調(diào)用參數(shù)
這篇文章給大家分享了PHP版本兼容之openssl調(diào)用參數(shù)的詳細(xì)說(shuō)明,有興趣的朋友參考學(xué)習(xí)下。2018-07-07php面向?qū)ο笾衧tatic靜態(tài)屬性與方法的內(nèi)存位置分析
這篇文章主要介紹了php面向?qū)ο笾衧tatic靜態(tài)屬性與方法的內(nèi)存位置,通過內(nèi)存位置實(shí)例分析了static靜態(tài)屬性的原理與使用技巧,需要的朋友可以參考下2015-02-02