get a PHP delete variable

前端 未结 4 1691
一整个雨季
一整个雨季 2021-02-07 04:25

If I am issuing an HTTP DELETE, how can I access the PHP body/variable? I know if you\'re issuing POST, you access it via $_POST[\'varname\'], but how do you access

4条回答
  •  有刺的猬
    2021-02-07 04:41

    file_get_contents('php://input') should always give you the complete request body. Note that it may be readable only once. The bigger question is whether a DELETE request may contain a body, which seems to be something of an unanswered question, but will probably work.

    I'd say sending the id in the body is somewhat RESTless though. The entity in question should be referred to by the URL as example.com/foo/42, so a DELETE request should say DELETE /foo/42, not DELETE /foo with the id in the request body.

提交回复
热议问题