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

如何从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条)

相关推荐 更多相似问题