使用PHP和CURL进行PUT请求

使用PHP和CURL进行PUT请求

本文介绍了使用PHP和CURL进行PUT请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我工作基于以下假设:
根据REST架构,您可以使用PUT创建一个新的资源,在我的情况下,一个文件与用户提供的附加信息。 p>

如果这个概念不正确,请让我知道,所以我从建筑的角度不要问一个不正确的问题。



我看到有两个与使用CURL的PUT请求相关的东西。



使用下面的方法,你可以像正常的POST请求一样发送一个数组。

 
curl_setopt($ ch,CURLOPT_CUSTOMREQUEST,PUT);

并使用:

 
curl_setopt $ ch,CURLOPT_PUT,1);

可以上传一个文件。



  • 相关?
  • 它们是互补方式,以在同一PUT请求中发送文件和一些元信息吗?
  • 上传文件并为其发送类别和说明的其他信息的解决方案



    只是试图模仿POST功能

     
    $ post_params ['name'] = urlencode('Test User');
    $ post_params ['file'] ='@'。'/ tmp / never_ending_progress_bar2.gif';


    解决方案

    CURLOPT_CUSTOMREQUEST



    CURLOPT_POST

    code>, 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.

  • Are this two options related ?
  • Are they complementarity ways to send both a file and some meta information in the same PUT request?
  • What is the solution to upload a file and send additional information for it like category and description

    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请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 07-28 00:36