Making a PUT request with PHP and CURL
First of all I'm working based on the following assumption: according to the REST architecture you can use PUT to create a new resource, in my case a file with additional informations provided by the user.
If this concept is not correct please let me know so I don't ask an incorrect question from the architectural point of view.
I see there are two things related to PUT request using CURL.
With the following method you can send an array of values just like a normal POST request.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
and using this:
curl_setopt($ch, CURLOPT_PUT, 1);
a file can be uploaded.
I'm just trying to mimic the POST functionality
$post_params['name'] = urlencode('Test User'); $post_params['file'] = '@'.'/tmp/never_ending_progress_bar2.gif';
CURLOPT_CUSTOMREQUEST
is useful when you want / need to do some kind of special request that is not common enough to be supported by itself, via its own option.
CURLOPT_POST
, CURLOPT_PUT
, and CURLOPT_GET
allow you to send POST
/ PUT
/ GET
requests -- which are some types of requests that are common enough to have their own options ; which means they don't need you to use CURLOPT_CUSTOMREQUEST
.
精彩评论