常規curl請求:curl
$url = 'http://www.xxx.com'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); var_dump($data);
使用curl請求HTTPS:url
$url = 'https://www.xxx.com'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//這個是重點。 $data = curl_exec($curl); curl_close($curl); var_dump($data);
注意spa
當請求https的數據時,會要求證書,這時候,加上下面這兩個參數,規避ssl的證書檢查設計
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https請求 不驗證證書和hosts curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
但願本文所述對你們的PHP程序設計有所幫助。code