我試圖經過curl鏈接從URL獲取JSON數據.當我打開連接時:它顯示{「version」:「N / A」,「success」:true,「status」:true}.
如今,我但願得到以上內容.php
到目前爲止我使用了這個:web
$loginUrl = 'http://update.protect-website.com/index.php?plugin=firewall&action=getVersion'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$loginUrl); $result=curl_exec($ch); curl_close($ch); var_dump(json_decode($result));
可是,我老是獲得NULL,有人知道哪裏出錯了嗎?json
該網站檢查用戶代理.添加代理選項,它將起做用.curl
$loginUrl = 'http://update.protect-website.com/index.php?plugin=firewall&action=getVersion'; $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$loginUrl); curl_setopt($ch, CURLOPT_USERAGENT, $agent); $result=curl_exec($ch); curl_close($ch); var_dump(json_decode($result));