我在这里看到了几个问题,例如 How to debug RESTful services ,其中提到:
Unfortunately that same browser won't allow me to test HTTP PUT, DELETE, and to a certain degree even HTTP POST.
我还从其他一些来源听说浏览器仅支持 GET 和 POST,例如:
- http://www.packetizer.com/ws/rest.html
- http://www.mail-archive.com/jmeter-user@jakarta.apache.org/msg13518.html
- http://www.xml.com/cs/user/view/cs_msg/1098
但是,Firefox 中的一些快速测试表明发送 PUT
和 DELETE
请求按预期工作 - XMLHttpRequest
成功完成,并且该请求以正确的方法显示在服务器日志中。我是否缺少某些方面,例如跨浏览器兼容性或不明显的限制?
最佳答案
没有。 HTML 5 spec提及:
The method and formmethod content attributes are enumerated attributes with the following keywords and states:
The keyword get, mapping to the state GET, indicating the HTTP GET method. The GET method should only request and retrieve data and should have no other effect.
The keyword post, mapping to the state POST, indicating the HTTP POST method. The POST method requests that the server accept the submitted form's data to be processed, which may result in an item being added to a database, the creation of a new web page resource, the updating of the existing page, or all of the mentioned outcomes.
The keyword dialog, mapping to the state dialog, indicating that submitting the form is intended to close the dialog box in which the form finds itself, if any, and otherwise not submit.
The invalid value default for these attributes is the GET state
即HTML 表单仅支持 GET 和 POST 作为 HTTP 请求方法。解决此问题的方法是使用隐藏的表单字段通过 POST 隧道其他方法,该字段由服务器读取并相应地分派(dispatch)请求。
但是,GET、POST、PUT 和 DELETE 支持 XMLHttpRequest(即 AJAX 调用)在所有主要 Web 浏览器(IE、Firefox、Safari、Chrome、Opera)中的实现。
关于http - PUT、DELETE、HEAD 等方法在大多数 Web 浏览器中都可用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11035927/