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 如何用python处理excel的数据(极值标准化)
  • ¥15 三向应力状态求剪应力
  • ¥15 jupyter notebook如何添加libGL.so.1库
  • ¥20 easyPoi能否实现下拉多选或者复选框
  • ¥15 网桥在转发帧时,会变帧的源地址和目的地址吗?
  • ¥15 用Multisim设计汽车尾灯控制电路
  • ¥100 求用matlab求解上述微分方程的程序代码
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析