详解php中curl返回false的解决办法

é¦åæ¥çä¸ä¸ªå°è£çcurlå½æ°

function request_post($url = '', $param = '') {
 if (empty($url) || empty($param)) {
 return false;
 }
 $postUrl = $url;
 $curlPost = $param;
 $curl = curl_init();//åå§åcurl
 curl_setopt($curl, CURLOPT_URL,$postUrl);//æåæå®ç½é¡µ
 curl_setopt($curl, CURLOPT_HEADER, 0);//设置header
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//è¦æ±ç»æ为å­ç¬¦ä¸²ä¸è¾åºå°å±å¹ä¸
 curl_setopt($curl, CURLOPT_POST, 1);//postæ交æ¹å¼
 curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);//æ交çåæ°
 $data = curl_exec($curl);//è¿è¡curl
 curl_close($curl);
 
 return $data;
}

è°ç¨çæ¶åè¿åç»æ为bool(false)

æ们å¨curl_execå½æ°åé¢éè¿curl_error($curl)è·åé误ä¹æ¯ string(0) "" 空å­ç¬¦ä¸²ã

æååç°èªå·±è°ç¨çapiçæ¥å£å°åæ¯sslåè®®çï¼ç¶åå ä¸ä¸é¢ä¸¤ä¸ªå°±å¯ä»¥äº

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

å¦æcurl请æ±çå°å中å«æ空格ä¹ä¼è¿åfalseçï¼è¿åä¹è¦æ ¼å¤æ³¨æã

ä¹åè¿éå°è¿ä¸ä¸ªè¿åfalseæå°curl_error($curl)å¾å°çæ¯å¦ä¸é误

string(39) "Problem (2) in the Chunked-Encoded data" bool(false)

è¿ä¸ªé误ç解å³åæ³è®¾ç½®curl使ç¨çHTTPåè®®çæ¬ï¼å°±æ¯å ä¸ä¸é¢è¿å¥

//CURL_HTTP_VERSION_1_0 (强å¶ä½¿ç¨ HTTP/1.0)
//CURL_HTTP_VERSION_1_1 (强å¶ä½¿ç¨ HTTP/1.1)ã
curl_setopt($curlp, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

以ä¸æè¿°æ¯å°ç¼ç»å¤§å®¶ä»ç»çphp中curlè¿åfalseç解å³åæ³è¯¦è§£æ´åï¼å¸æ对大家ææ帮å©ï¼å¦æ大家æä»»ä½çé®è¯·ç»æçè¨ï¼å°ç¼ä¼åæ¶åå¤å¤§å®¶çãå¨æ­¤ä¹é常æ谢大家对èæ¬ä¹å®¶ç½ç«çæ¯æï¼

相关推荐