1 回答
TA贡献1878条经验 获得超4个赞
原因是 API 提供商正在阻止 CLI 类型的用户代理,这很可能是为了防止机器人和此类事件。
如果您将用户代理设置为使用 cURL 模拟允许的浏览器,则它可以完美运行:
function getSslPage($url, $userAgent)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$url = "https://us.api.blizzard.com/data/wow/achievement/6?namespace=static-us&locale=en_US&access_token=USgdNPkRDwpJ1m4zQ2mHokA0O12E0kPTih";
$data = getSslPage($url, $userAgent);
print_r($data);
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报