我正在尝试让cloudflare的API输出格式化为JSON的一个域的DNS ZONE数据,我可以获得原始数据(但当我通过JSON解码进行解析时,我只得到单词ARRAY。
有人能告诉我哪里出了问题吗?这可能很明显,但我无法解决;
$headers = [
'X-Auth-Email: my@email.com',
'X-Auth-Key: jfjfh09xxxxxxxxx39nfh3',
'Content-Type: application/json'
];
$domain = "example.com"; //domain we're changing
$ZONE_ID="h4h4hxxxxxxxxxx8e3h4";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if (curl_errno($ch)) {
exit('Error: ' . curl_error($ch));
}
curl_close ($ch);
$json = json_decode($result, true);
echo $json;
我想继续使用php-cURL
您的代码还可以,但您使用echo
来显示数组。尝试使用var_dump()
或print_r()
。
print_r($json);