这是我尝试通过 api 删除文件的代码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/<MY-ZONE-ID>/purge_cache");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = [
'X-Auth-Email: MYEMAIL',
'X-Auth-Key: MY-AUTH-KEY',
'Content-Type: application/json'
];
$data = json_encode(array("files" => "https://example.com/file/".$filename));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
我得到的回复如下
{
"success":false,
"errors":[
{
"code":1012,
"message":"Request must contain one of \"purge_everything\" or \"files\", or \"tags"
}
],
"messages":[
],
"result":null
}
文档说标签是可选的,因此它应该可以工作
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/purge_cache" \
-H "X-Auth-Email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="582d2b3d2a183d20393528343d763b3735" rel="noreferrer noopener nofollow">[email protected]</a>" \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
-H "Content-Type: application/json" \
--data '{"files":["http://www.example.com/css/styles.css"],"tags":["some-tag","another-tag"]}'
这里做错了什么?
最佳答案
我可能是因为你的 files
属性不是数组。
尝试
$data = json_encode(array("files" => array("https://example.com/file/".$filename)));
关于php - 使用 cloudflare api 从缓存中删除文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42160784/