Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 解码json无法打开流:HTTP请求失败!错误_Php_Json_Decoding - Fatal编程技术网

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

Php 解码json无法打开流:HTTP请求失败!错误,php,json,decoding,Php,Json,Decoding,我获取文件\u获取\u内容(https://koinex.in/api/ticker):无法打开流:HTTP请求失败!错误 我做错了什么?您可以尝试以下方法: $context = stream_context_create([ 'http'=> [ 'method'=> 'GET', 'user_agent'=> $_SERVER['HTTP_USER_AGENT'] ] ]); $data = json_decod

我获取
文件\u获取\u内容(https://koinex.in/api/ticker):无法打开流:HTTP请求失败!错误


我做错了什么?

您可以尝试以下方法:

$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
在浏览器中工作,因此您似乎只需设置一个
用户代理
即可欺骗服务器,使其知道请求是由真正的用户使用浏览器发出的。另请阅读。

检查: