向外部API发送DELETE请求


Send DELETE request to the external API

我必须向外部缓存API发送一个DELETE请求。我该怎么做?我一直在考虑使用file()函数,比如:

file('https://someurl.com/api?parameter1=foo&parameter2=bar');

但首先它无法识别响应的类型,其次它抛出了一个错误:

Failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in。。。它似乎将"与"符号转换为&(至少xdebug显示了这一点)。

我该如何解决这个问题?

使用cURL:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($ch);