2014-04-17 20:18
浏览 53

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

I'm currently building a project based on the 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 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>" \<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_SSL_VERIFYPEER => false,
        CURLOPT_HTTPHEADER => array(
            'X-Parse-Application-Id: <YOUR_APPLICATION_ID>',
            'X-Parse-Master-Key: <YOUR_MASTER_KEY',
        CURLOPT_URL => '<FILE_NAME>',
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);
    echo $response;
    解决 无用
    打赏 举报

相关推荐 更多相似问题