无法解码嵌套的json api php
我正在使用这些代码获取KoinExAPI数据。从该API URL-无法解码嵌套的json api php,php,json,api,nested,Php,Json,Api,Nested,我正在使用这些代码获取KoinExAPI数据。从该API URL- 我也尝试了文件内容,但同样的问题。我在另外两个api中遇到了这个问题。注意:一旦我获得数据并正确使用它,但今天这就不再起作用了。我尝试了你的代码,显然你试图使用CURL访问的网站使用了一种安全机制: 我为什么被阻止? 此网站正在使用安全服务保护自己免受在线攻击。您刚才执行的操作触发了安全解决方案。有几个操作可能触发此块,包括提交某个单词或短语、SQL命令或格式错误的数据 如何解决此问题? 你可以给网站所有者发电子邮件,让他
我也尝试了文件内容,但同样的问题。我在另外两个api中遇到了这个问题。注意:一旦我获得数据并正确使用它,但今天这就不再起作用了。我尝试了你的代码,显然你试图使用CURL访问的网站使用了一种安全机制: 我为什么被阻止? 此网站正在使用安全服务保护自己免受在线攻击。您刚才执行的操作触发了安全解决方案。有几个操作可能触发此块,包括提交某个单词或短语、SQL命令或格式错误的数据 如何解决此问题? 你可以给网站所有者发电子邮件,让他们知道你被阻止了。请包括出现此页面时您正在执行的操作以及在此页面底部找到的Cloudflare Ray ID 您试图访问的网站似乎要求用户代理。此代码适用于我:
<?php
$getCurrency = "inr";
$displayArrayOutput = true;
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://koinex.in/api/ticker',
CURLOPT_USERAGENT => 'Something here'
));
// Send the request & save response to $resp
$response = curl_exec($curl);
// Close request to clear up some resources
$err = curl_error($curl);
curl_close($curl);
if ($err) {
} else {
if($displayArrayOutput){
$response = json_decode($response, true);
print_r($response);
}
else{
header("Content-type:application/json");
echo 'touine';
}
}
?>
祝你好运,
curl\u close
不会释放所有资源吗?那么,$response
不是空的吗?不是@Tony$已分配响应,它不是引用。捕捉良好。当我测试它时,一切正常,我正要抛出“无法复制”:
<?php
$getCurrency = "inr";
$displayArrayOutput = true;
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://koinex.in/api/ticker',
CURLOPT_USERAGENT => 'Something here'
));
// Send the request & save response to $resp
$response = curl_exec($curl);
// Close request to clear up some resources
$err = curl_error($curl);
curl_close($curl);
if ($err) {
} else {
if($displayArrayOutput){
$response = json_decode($response, true);
print_r($response);
}
else{
header("Content-type:application/json");
echo 'touine';
}
}
?>