douyuan4825 2014-04-17 20:18
浏览 57
已采纳

如何从PHP运行此REST API调用?

I'm currently building a project based on the Parse.com backend that includes uploading files. Users can upload files and then access a list of these/download them, this all works fine. However, I'm not sure how to implement the command to delete an upload. From the Parse.com forums as well as the Parse support document, the call is:

curl -X DELETE \
    -H "X-Parse-Application-Id: <YOUR_APPLICATION_ID>" \
    -H "X-Parse-Master-Key: <YOUR_MASTER_KEY>" \
    https://api.parse.com/1/files/<FILE_NAME>

I've had a bit of a look online but the only curl commands I can find to execute commands is curl_setopt. I imagine the above needs to be converted, can anybody help with this or point me in the right direction?

So basically I need to be able to press a button on a website (through PHP) and have it run the above command.

Thanks in advance

  • 写回答

2条回答 默认 最新

  • douzhanbai9526 2014-04-17 20:37
    关注

    According to given info you have to set custom request method 'DELETE' (by CURLOPT_CUSTOMREQUEST option) as well as custom headers (by CURLOPT_HTTPHEADER option).

    So the code should look like this:

    $options = array(
        CURLOPT_NOBODY => 0,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_CUSTOMREQUEST => 'DELETE',
        CURLOPT_HTTPHEADER => array(
            'X-Parse-Application-Id: <YOUR_APPLICATION_ID>',
            'X-Parse-Master-Key: <YOUR_MASTER_KEY',
        ),
        CURLOPT_URL => 'https://api.parse.com/1/files/<FILE_NAME>',
    );
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);
    echo $response;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料