简体   繁体   中英

Translate command CURL to PHP CURL? Cloudflare API

I am trying to use the CloudFlare API via PHP CURL however the doc examples show as command line 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":{}}'

Is the PUT request the same as POST? And the array at the bottom is confusing me. No idea how that translates to PHP CURL.

You will need to do a post but also send a custom request. Curl will then do a post style put

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");  
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 

Then add the headers if needed

curl_setopt($ch, CURLOPT_HTTPHEADER, [array of your headers]);

Change the array to be a key value array where the key is the header name and value is the header value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM