使用 Chrome 检查 url: http: //www.wizards.com/Magic/PlaneswalkerPoints/76954206#我可以看到获取 JSON 数据的 url:
请求网址: http: //www.wizards.com/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/76954206
运行我的代码:
$user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // times out after 5s
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($json)));
curl_setopt($ch, CURLOPT_POST, 1);
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") {
print_r($ch);
} else {
echo "Boo";
}
给我留下一个空白页。它不返回 JSON,只返回重定向错误页面。
我是否缺少某个调用来获取 JSON 数据?