无法在具有自定义标头和一些数据的PHP中使用curl

时间:2017-08-11 02:28:33

标签: php api curl cloudflare

我使用cloudflare的API来管理我的网站,它的文档说明了这个 -

curl -X POST "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records" \
 -H "X-Auth-Email: user@example.com" \
 -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
 -H "Content-Type: application/json" \
 --data '{"type":"A","name":"example.com","content":"127.0.0.1","ttl":120,"proxied":false}'

我试过的PHP代码就是这个 -

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.cloudflare.com/client/v4/zones/92g6wwa3794g8wsf040s9t12a511a3/dns_records");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'{"type":"A","name":"example.com","content":"127.0.0.1","ttl":120,"proxied":false}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Auth-Email: email@mail.com',
'X-Auth-Key: bf1f67fdjbdkhwois56465813fcdb7',
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo $server_output;
?>

它正在使用实际主机但不在localhost上工作。 但我得到空洞的结果, 我在这做错了什么?

0 个答案:

没有答案