解码json无法打开流:HTTP请求失败!错误

时间:2018-02-16 09:51:12

标签: php json decoding

我得到file_get_contents(https://koinex.in/api/ticker):failed to open stream: HTTP request failed! error

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

$context = stream_context_create([ 
    'http'=> [ 
        'method'=> 'GET', 
        'user_agent'=> $_SERVER['HTTP_USER_AGENT'] 
    ]
]); 

$data = json_decode(
    file_get_contents('https://koinex.in/api/ticker', false, $context)
);

以下https://koinex.in/api/ticker可以在浏览器中运行,因此您似乎需要设置user_agent来欺骗服务器,使真实用户使用浏览器进行请求。另请阅读stream_context_create