问题描述
首先,我工作基于以下假设:
根据REST架构,您可以使用PUT创建一个新的资源,在我的情况下,一个文件与用户提供的附加信息。 p>
如果这个概念不正确,请让我知道,所以我从建筑的角度不要问一个不正确的问题。
我看到有两个与使用CURL的PUT请求相关的东西。
使用下面的方法,你可以像正常的POST请求一样发送一个数组。
curl_setopt($ ch,CURLOPT_CUSTOMREQUEST,PUT);
并使用:
curl_setopt $ ch,CURLOPT_PUT,1);
可以上传一个文件。
只是试图模仿POST功能
$ post_params ['name'] = urlencode('Test User');
$ post_params ['file'] ='@'。'/ tmp / never_ending_progress_bar2.gif';
CURLOPT_CUSTOMREQUEST
CURLOPT_POST
CURLOPT_PUT
和 CURLOPT_GET
允许您发送 POST
/ PUT
/ GET
请求 - 这是一些类型的请求,自己的选择;这意味着他们不需要你使用 CURLOPT_CUSTOMREQUEST
。 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
.
这篇关于使用PHP和CURL进行PUT请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!