使用curl从opendatacommunities.org获取数据

时间:2018-06-16 09:18:14

标签: api curl

我想使用opendatacommunities.org的API

以下代码用于相同的代码。但我得到了一个没有可接受的资源"消息

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, https://epc.opendatacommunities.org/api/v1/domestic/search?address=liverpool"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0")
$headers = array(); 
$headers[] = "Accept: text/json"; 
$headers[] = "Authorization: Basic XXXXXXXXXXXXXXX";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
if (curl_errno($ch)) { 
echo 'Error:' . curl_error($ch); } 
curl_close ($ch);

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您好我能够将其修复为代码

$headers[] = "Accept: text/json"; 

替换为

$headers[] = "Accept: application/json"; 

感谢您帮助DhamankarTejas