我正在尝试通过PHP CURL使用CloudFlare API,但文档示例显示为命令行卷曲。
$ curl -X PUT "https://api.cloudflare.com/client/v4/zones/9a7806061c88ada191ed06f989cc3dac/dns_records/9a7806061c88ada191ed06f989cc3dac" \
-H "X-Auth-Email: user@example.com" \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
-H "Content-Type: application/json" \
--data '{"id":"9a7806061c88ada191ed06f989cc3dac","type":"A","name":"example.com","content":"1.2.3.4","proxiable":true,"proxied":false,"ttl":120,"locked":false,"zone_id":"9a7806061c88ada191ed06f989cc3dac","zone_name":"example.com","created_on":"2014-01-01T05:20:00.12345Z","modified_on":"2014-01-01T05:20:00.12345Z","data":{}}'
PUT请求与POST相同吗?底部的数组令我困惑。不知道如何转换为PHP CURL。
答案 0 :(得分:1)
您需要发帖,但也要发送自定义请求。然后Curl会做一个帖子样式放置
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
然后根据需要添加标题
curl_setopt($ch, CURLOPT_HTTPHEADER, [array of your headers]);
将数组更改为键值数组,其中键是标题名称,值是标题值