gpt4 book ai didi

php - PHP curl DELETE请求的写法

转载 作者:行者123 更新时间:2023-12-02 06:15:06 31 4
gpt4 key购买 nike

我正在引用 DigitalOcean 的 API 文档,他们给出了以下关于如何在此处删除 droplet 的示例:

curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer API_TOKEN" "https://api.digitalocean.com/v2/droplets/[DROPLET_ID]"

我如何用 PHP curl 编写这个?

我目前有这个:

$ch = curl_init('https://api.digitalocean.com/v2/droplets/18160706');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer MY_API_TOKEN')
);

$result = curl_exec($ch);
echo $result;

但这并没有删除我的 droplet 并且正在返回(是的,droplet id 是正确的):

{"id":"not_found","message":"The resource you were accessing could not be found."}1

最佳答案

试试这个

将 CUTLOPT_CUSTOMREQUEST 更改为“DELETE”Find More

$ch = curl_init('https://api.digitalocean.com/v2/droplets/18160706');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer MY_API_TOKEN')
);

$result = curl_exec($ch);
echo $result;

关于php - PHP curl DELETE请求的写法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38035010/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com