How to enable and use HTTP PUT and DELETE with Apache2 and PHP?

后端 未结 6 408
别跟我提以往
别跟我提以往 2020-11-29 04:55

It should be so simple. I\'ve followed every tutorial and forum I could find, yet I can\'t get it to work. I simply want to build a RESTful API in PHP on Apache2.

In

6条回答
  •  感动是毒
    2020-11-29 05:05

    IIRC the purpose of the form method attribute was to define different transport methods. Consequently, HTML 5.2 only defines GET, POST, and DIALOG methods for transport and dialog action, not how the server should process the data.

    Ruby-on-rails solves this problem by using POST/GET for everything and adding a hidden form variable that defines the actual ReST method. This approach is more clumsy and error-prone, but does remove the burden from both the HTML standard and browser developers.

    The form method was defined before ReST, so you cannot define ReST in HTML, even after enabling Apache and PHP because the browsers conform to HTML and therefore default to GET/POST for all non-HTML defined values. That means, when you send a form to the browser with a PUT method, the browser changes that to GET and uses that instead. The hidden variable, however, passes through everything unchanged, so you can use that to customise your form handling process.

    Hope that helps

提交回复
热议问题