将命令 CURL 转换为 PHP CURL? Cloudflare API
Translate command CURL to PHP CURL? Cloudflare API
我正在尝试通过 PHP CURL 使用 CloudFlare API,但是文档示例显示为命令行 curl。
$ 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。
您需要执行 post,但也需要发送自定义请求。然后 Curl 将执行 post 样式 put
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
然后根据需要添加 headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [array of your headers]);
将数组更改为键值数组,其中键是 header 名称,值是 header 值
我正在尝试通过 PHP CURL 使用 CloudFlare API,但是文档示例显示为命令行 curl。
$ 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。
您需要执行 post,但也需要发送自定义请求。然后 Curl 将执行 post 样式 put
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
然后根据需要添加 headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [array of your headers]);
将数组更改为键值数组,其中键是 header 名称,值是 header 值