码迷,mamicode.com
首页 > Web开发 > 详细

php – 通过curl从url获取JSON数据

时间:2019-08-16 18:39:56      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:update   ref   res   result   top   显示   cti   code   ati   

我试图通过curl连接从URL获取JSON数据.当我打开链接时:它显示{“version”:“N / A”,“success”:true,“status”:true}.
现在,我希望获得以上内容.

到目前为止我使用了这个:

$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,有人知道哪里出错了吗?

该网站检查用户代理.添加代理选项,它将起作用.

$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));

  

php – 通过curl从url获取JSON数据

标签:update   ref   res   result   top   显示   cti   code   ati   

原文地址:https://www.cnblogs.com/lxwphp/p/11365452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!