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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度