Wednesday, January 31, 2024

[SOLVED] Send `PUT` and `DELETE` request using CURL

Issue

Is it possible to send PUT and DELETE request using curl. As we send POST and GET request in curl:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");             
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

How to send PUT and DELETE request.


Solution

You can use the CURLOPT_CUSTOMREQUEST option like so:

curl_setopt($curlObject, CURLOPT_CUSTOMREQUEST, "DELETE");

Here, $curlObject is the result obtained from curl_init.

This is all detailed on the relevant API reference page:

http://php.net/manual/en/function.curl-setopt.php



Answered By - user5294349
Answer Checked By - Marilyn (WPSolving Volunteer)