dongpo1846 2013-04-22 12:30
浏览 34
已采纳

在php中抓取https json url [关闭]

I have been using this code for the past 2-3 months to grab json data variables that are needed. When the url changes to https:// it errors out and won't display. Is there a different way to grab https from http for json url's and php? I can't seem to find anything in terms of a good example or documentation.

<?
$btcjsonurl = "http://blockchain.info/stats?format=json";
$btcjson = file_get_contents($btcjsonurl,0,null,null);
$btcdata = json_decode($btcjson, true);
$btcdiff = $btcdata['difficulty'];
echo $btcdiff;
?>
  • 写回答

2条回答 默认 最新

  • dongpenggan6812 2013-04-22 12:35
    关注

    What's the error?

    See this (possible dupe)

    Unless, is there any reason why you can't use curl, or a similar php client?

    Https requires extra client side implementation for SSL etc, whereas all file_get_contents, called without $opts, will do functionally is read a file stream. For example, if the hostname in the SSL certificate is not the one in the link you pass to file get contents, the implementation of https requires you- the client- to verify this (typically by looking up in a list of allowed host you would need to manually write). But because you're not working directly with a client, you have no opportunity to handle this.

    Another route would be to use stream_context_create of course, but that's covered in the link above so I won't repeat it.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀