2012-01-20 77 views
0

我使用下面的代碼來訪問一個網址(URL使用https協議,並具有有效的證書)使用cURL從https讀取響應

// Initialize session and set URL. 
$url = https://my url; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 

// Set so curl_exec returns the result instead of outputting it. 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

// Get the response and close the channel. 
$response = curl_exec($ch); 
curl_close($ch); 

但輸出我得到的是這樣的:

Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

有人能指導我嗎?

回答

2

使用 'CURLOPT_RETURNTRANSFER'

$res = curl_init ('url'); 
curl_setopt($res,CURLOPT_RETURNTRANSFER,true); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
$out = curl_exec($res); 
curl_close($res); 
echo $out; 

更多信息讀取this

+0

謝謝,至於我能理解,您提供的代碼片段將再次SSL證書?我對嗎? –

+1

@NewBee是的,你需要嗎?還要別的嗎 ? – Dau

+0

謝謝,我想學習的東西,現在我將嘗試解析輸出,並保存在XMl,試圖學習,學習和學習,感謝幫助男孩... –

0

嘗試增加:

 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
 
+0

感謝您的指導,我怎麼能在裏面添加SSL證書?避免衝突? –