How to set the cURL request method to PUT or DELETE in PHP?

To set the cURL request method to PUT or DELETE in PHP, you can use the curl_setopt() function.

Here's an example of how to do it:

For PUT request:

// Initialize cURL $curl = curl_init(); // Set the URL curl_setopt($curl, CURLOPT_URL, "https://example.com/api/endpoint"); // Set the request method to PUT curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); // Execute the request $response = curl_exec($curl); // Close cURL session curl_close($curl);

For DELETE request:

// Initialize cURL $curl = curl_init(); // Set the URL curl_setopt($curl, CURLOPT_URL, "https://example.com/api/endpoint"); // Set the request method to DELETE curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); // Execute the request $response = curl_exec($curl); // Close cURL session curl_close($curl);

In both cases, you first initialize the cURL session using curl_init(), then set the URL with CURLOPT_URL, followed by setting the request method to PUT or DELETE using CURLOPT_CUSTOMREQUEST.

Finally, you execute the request with curl_exec(), capture the response if needed, and close the cURL session with curl_close().