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条)

报告相同问题?