php抓取https的內(nèi)容的代碼
更新時間:2010年04月06日 21:22:38 作者:
有時候需要獲取https網(wǎng)頁的內(nèi)容,下面得方法,可以參考下。
直接用file_get_contents,會報錯;
$url = (https://xxx.com");
file_get_contents($url);
錯誤:
Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3
用curl的方式是可以的:
$url = (https://xxx.com);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
print_r($result);
?>
重點是以下兩句:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
復制代碼 代碼如下:
$url = (https://xxx.com");
file_get_contents($url);
錯誤:
Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3
用curl的方式是可以的:
復制代碼 代碼如下:
$url = (https://xxx.com);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
print_r($result);
?>
重點是以下兩句:
復制代碼 代碼如下:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
您可能感興趣的文章:
- PHP獲取http請求的頭信息實現(xiàn)步驟
- php之curl實現(xiàn)http與https請求的方法
- PHP實現(xiàn)取得HTTP請求的原文
- php中調(diào)用其他系統(tǒng)http接口的方法說明
- PHP 使用header函數(shù)設(shè)置HTTP頭的示例解析 表頭
- php curl 獲取https請求的2種方法
- 在PHP中實現(xiàn)使用Guzzle執(zhí)行POST和GET請求
- 在Laravel中使用GuzzleHttp調(diào)用第三方服務(wù)的API接口代碼
- 使用Zttp簡化Guzzle 調(diào)用
- PHP的HTTP客戶端Guzzle簡單使用方法分析
相關(guān)文章
PHP+HTML+JavaScript+Css實現(xiàn)簡單爬蟲開發(fā)
這篇文章主要為大家詳細介紹了PHP+HTML+JavaScript+Css實現(xiàn)簡單爬蟲開發(fā),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-03-03詳解cookie驗證的php應(yīng)用的一種SSO解決辦法
這篇文章主要介紹了詳解cookie驗證的php應(yīng)用的一種SSO解決辦法的相關(guān)資料,希望通過本文能幫助到大家讓大家遇到這種類似問題解決,需要的朋友可以參考下2017-10-10安裝apache2.2.22配置php5.4(具體操作步驟)
本篇文章是對安裝apache2.2.22配置php5.4的具體操作步驟進行了詳細的分析介紹,需要的朋友參考下2013-06-06